Uh oh!
There was an error while loading. Please reload this page.
[Feat] Room 도입과 운동 기록 캐시 저장층 추가 - #591
Open
edv-Shin wants to merge 3 commits into
Open
Conversation
오프라인 캐시의 저장층입니다. 아직 아무도 이 DB를 주입받지 않습니다. - 모든 테이블에 memberId 컬럼을 두고 조회에 계정 조건을 겁니다 - 목록과 상세는 테이블을 나눴습니다. 한 테이블에 담으면 목록 응답을 저장할 때 detail과 location이, 상세를 저장할 때 date와 thumbnailUrls가 서로 덮여 사라집니다 - 목록의 date는 조회할 때 서버에 넘긴 날짜입니다. startedAt에서 파생시키면 자정을 넘긴 기록이 서버가 묶어준 날과 어긋납니다 - sortOrder는 서버 응답 순서입니다. SQL이 순서를 보장하지 않습니다 - 날짜는 ISO 문자열로 담아 사전순 비교가 시간순 비교가 되게 했고, 사진 목록은 JSON 컬럼입니다
계정 경계를 테이블보다 먼저 잠급니다. 로그아웃이나 계정 전환 때 이전 사용자의 데이터가 남으면 안 됩니다. - 세션을 지우는 경로가 MainViewModel.transitionToLogin()과 SettingFragment.clearLocalSession() 둘인데 모두 ClearSessionUseCase를 거치므로 삭제를 여기 한 곳에 연결합니다 - domain은 Room을 모르게 합니다. FcmTokenSyncScheduler와 같은 패턴으로 domain에 SessionDataCleaner 인터페이스를 두고 data 구현이 지웁니다
기존 API 호출을 RemoteDataSource로 옮기고 Room 접근을 LocalDataSource로 분리합니다. apiCallBuilder 계약과 화면 동작은 그대로입니다. - LocalDataSource가 memberId를 자기 안에서만 읽습니다. 호출부가 넘길 수 없으니 계정 조건을 빠뜨린 쿼리를 쓸 자리가 없습니다 - 캘린더와 목록은 구간을 비우고 다시 채웁니다. 서버 응답에는 운동한 날과 남아 있는 기록만 오니까 upsert만 하면 0건이 된 날과 삭제된 기록이 캐시에 계속 남습니다 - LocalDataSource는 아직 호출부가 없습니다. 읽기를 Flow로 바꾸는 건 #584입니다
6 tasks
This file contains hidden or 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
Sign up for freeto 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.
#️⃣연관된 이슈
Closes#581, Closes#583
📝작업 내용
오프라인 캐시의 저장층을 올립니다. 화면에 보이는 변화는 없고, 읽기 경로를 Flow로 바꾸는 건 #584에서 합니다.
Room은 entities가 빈 데이터베이스를 컴파일 에러로 막아서 #581만 따로 올릴 수 없었습니다. 그래서 #583의 Entity와 DAO를 함께 담았습니다.
Room 골격과 계정 스코프 (#581)
운동 기록 캐시 (#583)
ktlintCheck, testDebugUnitTest, assembleDebug 모두 통과했습니다.
스크린샷 (선택)
💬리뷰 요구사항(선택)
1. 기록의 신원을 지금 바꿔야 할지
지금 PK가 (memberId, recordId: Long)이라 서버 ID가 없는 로컬 기록은 들어갈 자리가 없습니다. 운동 기록 CRUD가 범위에 들어오면 오프라인에서 만든 기록이 목록에 즉시 보여야 하는데, PK를 localId(UUID)로 바꾸고 serverId를 nullable로 두는 모양이 필요합니다.
exercise_nav_graph.xml의 recordId: long 7곳도 함께 걸립니다. #584가 그 ViewModel들을 건드리는 이슈라, Long으로 한 번 전환하고 CRUD에서 UUID로 다시 전환하면 같은 파일을 두 번 고칩니다. DB가 아직 배포된 적이 없어서 지금 바꾸면 마이그레이션 비용이 0입니다.
2. 목록과 상세 테이블 분리
upsert 충돌을 피하려고 나눴는데 title, startedAt, endedAt이 양쪽에 중복됩니다. 한 테이블에 두고 부분 컬럼 UPDATE 쿼리 두 개로 가는 선택지도 있었습니다. 어느 쪽이 나을지 봐주시면 좋겠습니다.
3. DAO 테스트를 뺀 판단
메모리 DB로 DAO를 테스트하려면 Robolectric이 필요한데(CI가 testDebugUnitTest만 돌려서 androidTest는 실행되지 않습니다), data 모듈에 테스트가 하나도 없는 상태에서 90MB 인프라를 들이는 게 맞나 싶어 뺐습니다. 지금 SQL은 단순 조회고 틀리면 화면에 바로 보입니다. 다만 CRUD 단계의 syncState 전이와 대기 행 보존 쿼리는 성격이 달라서 그때는 다시 넣을 생각입니다.