Skip to content
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

post_write_page.dart에서 게시판 목록 caching #178

Merged
merged 3 commits into from
Apr 22, 2024

Conversation

thomaskim1130
Copy link
Contributor

updateStateWithCachedOrFetchedApiData 함수를 사용해 게시판 목록 caching 기능 추가.

Overview

게시물 작성 페이지에서 게시판 목록 캐싱 기능 추가.

Changes

  • 게시판 목록을 자동으로 SharedPreferences에 저장.

Implementaion Method

  • updateStateWithCachedOrFetchedApiData 함수를 사용 (cache_function.dart)

After Changes

  • 게시물 작성 페이지 로딩 속도 감소

Related Issues

  • initState부터 함수가 호출되기 때문에 await를 사용해야 정상적으로 작동됨.

Rollback Scenario

TODO

updateStateWithCachedOrFetchedApiData 함수를 사용해 게시판 목록 caching 기능 추가.
@thomaskim1130 thomaskim1130 linked an issue Apr 6, 2024 that may be closed by this pull request
@thomaskim1130 thomaskim1130 self-assigned this Apr 6, 2024
@thomaskim1130 thomaskim1130 requested a review from sangohkim April 6, 2024 17:56
@thomaskim1130 thomaskim1130 added the enhancement New feature or request label Apr 6, 2024
@thomaskim1130 thomaskim1130 added this to the v1.1.0 milestone Apr 6, 2024
@thomaskim1130 thomaskim1130 marked this pull request as ready for review April 6, 2024 17:56
apiUrl: "boards/", // API URL을 지정합니다. 이 예에서는 "boards/"를 대상으로 합니다.
userProvider: userProvider, // API 요청을 담당할 userProvider 인스턴스를 전달합니다.
callback: (response) {
try {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DioException은 updateStateWithCatchedOrFetchedApiData 함수 내에서 userProvider.getApiRes가 처리하기 때문에 여기서 처리하실 필요 없습니다. callback 내부를

if (mounted) {
              setState(() {
                // `_boardList` 초기화 후 기본 게시판 추가.
                _boardList = [_defaultBoardDetailActionModel];

                // Json 응답에서 게시물 목록 파싱 후 `_boardList`에 추가.
                for (Map<String, dynamic> boardJson in response) {
                  try {
                    BoardDetailActionModel boardDetail =
                        BoardDetailActionModel.fromJson(boardJson);
                    if (boardDetail.user_writable) {
                      _boardList.add(boardDetail);
                    }
                  } catch (error) {
                    debugPrint(
                        "refreshBoardList BoardDetailActionModel.fromJson 실패: $error");
                    return;
                  }
                }
              });
            }

위 코드로만 전달하셔도 무방합니다.

Copy link
Collaborator

@sangohkim sangohkim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

기능은 정상 동작합니다! 없어도 되는 코드 수정 요청 드렸어요

updateStateWithCachedOrFetchedApiData 함수에서 이미 구현된 (getApiRes) DioException Handling 제거
@thomaskim1130 thomaskim1130 requested a review from sangohkim April 22, 2024 14:54
Copy link
Collaborator

@sangohkim sangohkim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@sangohkim sangohkim merged commit 0365fbf into dev Apr 22, 2024
2 checks passed
@thomaskim1130 thomaskim1130 deleted the feat/write-page-cache branch April 22, 2024 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] PostWritePage cache 적용하기
2 participants