-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Caching 속도 최적화 및 임시 저장 수정 #219
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
기존의 caching 지연 원인 : cache는 SharedPreferences에서 잘 호출되었으나, 업데이트하는 과정에서 _isLoading=false가 늦게 호출 (updateStateWithFetchedOrCachedData 완료 이후)되면서 로딩화면이 계속됨. 해결책 : _getCachedContents, _getBoardList (임시 저장, 게시판 목록)을 순서대로 불러와 최종적으로 _getBoardList의 업데이트에 따라 setState가 호출되도록 변경. 또한 _isLoading=false 를 setState() 내부에 통합시킴으로써 바로 화면이 build되도록 변경.
_getCachedData를 불러오는 과정에서, 수정(_isEditingPost) 중이면 캐시를 불러오지 않도록 수정함. 또한 _getCachedData를 _getBoardList 안으로 편입시켜 _boardList를 모두 가져온 후에만 캐싱하도록 해 오류를 제거함. +removeApiData 함수를 정의해 null로 정의하는 메커니즘을 변경함.
Closed
thomaskim1130
changed the title
[Feature] Caching 속도 최적화 및 임시 저장 수정
Caching 속도 최적화 및 임시 저장 수정
Aug 29, 2024
sangohkim
requested changes
Aug 30, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이제 로딩없이 속도가 정말 빨라졌네요! 사용자 경험 향상에 큰 도움이 될 것 같아요 👍
수정 요청사항이 몇가지 있는데
- 해당 PR의 변경 사항이 아닌 부분도 있지만 async 블럭 내에서 context를 사용하는 부분 코드 보완을 부탁드립니다.
- 수정해야하는 이유는 관련 공식 문서
- 본 PR 기준으로 548, 552, 626, 636, 650번째 줄을 수정해주시면 됩니다
- 링크한 공식문서에서 제시하는 수정방법을 따라가시면 됩니다
if (mounted)
또는if (context.mounted)
추가
- iOS, Android 기기에서 기존의 글에 '수정하기'를 누른 이후에 뒤로가기 버튼을 누른 후 ExitConfirmDialog에서 '임시저장하기'를 누르면 에러가 발생합니다! 본 PR의 변경사항에 의해서 발생하는 것인지 확인해주시면 좋을 것 같습니다.
- 조금 더 확인해보니 iOS에서는 가끔 정상작동할때도 있고
flutter: updateStateWithCachedOrFetchedApiData error: setState() callback argument returned a Future.
flutter: The setState() method on _PostWritePageState#e269b was called with a closure or method that returned a Future. Maybe it is marked as "async".
flutter: Instead of performing asynchronous work inside a call to setState(), first execute the work (without updating the widget state), and then synchronously update the state inside a call to setState()., apiurl: boards/
- 안드로이드에서는 수정하기 이후 임시저장하려고하면 항상
E/flutter (12516): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Converting object to an encodable object failed: Instance of 'AttachmentsFormat'
E/flutter (12516): #0 _JsonStringifier.writeObject (dart:convert/json.dart:793:7)
E/flutter (12516): #1 _JsonStringifier.writeList (dart:convert/json.dart:841:7)
E/flutter (12516): #2 _JsonStringifier.writeJsonValue (dart:convert/json.dart:823:7)
E/flutter (12516): #3 _JsonStringifier.writeObject (dart:convert/json.dart:784:9)
E/flutter (12516): #4 _JsonStringifier.writeMap (dart:convert/json.dart:874:7)
E/flutter (12516): #5 _JsonStringifier.writeJsonValue (dart:convert/json.dart:829:21)
E/flutter (12516): #6 _JsonStringifier.writeObject (dart:convert/json.dart:784:9)
E/flutter (12516): #7 _JsonStringStringifier.printOn (dart:convert/json.dart:982:17)
E/flutter (12516): #8 _JsonStringStringifier.stringify (dart:convert/json.dart:967:5)
E/flutter (12516): #9 JsonEncoder.convert (dart:convert/json.dart:345:30)
E/flutter (12516): #10 JsonCodec.encode (dart:convert/json.dart:231:45)
E/flutter (12516): #11 jsonEncode (dart:convert/json.dart:114:10)
E/flutter (12516): #12 cacheApiData (package:new_ara_app/utils/cache_function.dart:12:23)
E/flutter (12516): <asynchronous suspension>
E/flutter (12516): #13 _PostWritePageState.cacheCurrentData (package:new_ara_app/pages/post_write_page.dart:295:5)
E/flutter (12516): <asynchronous suspension>
E/flutter (12516): #14 _PostWritePageState._buildAppBar.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:new_ara_app/pages/post_write_page.dart:634:25)
E/flutter (12516): <asynchronous suspension>
E/flutter (12516):
BuildContext context를 async 함수 내에서 사용하는 것을 if (mounted) {} 문으로 감싸 오류를 해결함.
updateStateWithCachedOrFetchedApiData의 callback 함수 중, setState() 를 async하게 설정한 문제를 해결함. callback 자체를 async로 설정 후, 리스트를 의 copy를(newChosenBoard etc.) 사용해 setState() 내부에서만 synchronous하게 정의하도록 변경함.
sangohkim
approved these changes
Sep 1, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
Cache 저장 및 불러오기의 속도를 대폭 증가시킴.
Changes
Implementaion Method
After Changes
Related Issues
Rollback Scenario
TODO