🐛 [fix] CloudKit 동기화 데이터 유실 방지 강화#172
Merged
Merged
Conversation
- 기존 유저 플래그(hasEverHadUserCollection) 도입하여 앱 업데이트/iCloud 재구성 시 빈 UC 자동 생성으로 인한 클라우드 데이터 오염 차단 - Grace period 30초 → 120초 연장 (대용량 re-import 대응) - DailyTask 기본값 자동 생성에 shouldSuppressDataCreation 통합 보호 적용 - 의도적 데이터 초기화 시 hasEverHadUserCollection 리셋 (clearHasEverHadUserCollection) - 설정 화면에 동기화 상태 표시 (로컬 레코드 수, 마지막 동기화 시각, 동기화 진행 상태)
Release 빌드에서도 에러 추적이 가능하도록 모든 CoreData Storage 클래스와 Items.swift, TasksEditReactor의 debugPrint(error)를 os_log(.error)로 교체
- Known User Protection (hasEverHadUserCollection) 섹션 추가 - shouldSuppressDataCreation 통합 프로퍼티 설명 - UC 생성 억제 조건 4가지 → 5가지로 업데이트 (grace period 120초) - Sync Status Display 섹션 추가 - Error Logging 강화 섹션 추가
- "로컬 레코드: N개" → "N개 저장됨" (사용자 친화적 문구) - 동기화 시각 있을 때 "3분 전 동기화 · N개 저장됨" 형태로 통합 - 여러 줄 → 한 줄 표시 (numberOfLines=1, textAlignment=.right)
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
- grace period 상수(120s) + isWithinGracePeriod 추출 (DRY) - entityCounts(in:) 헬퍼 추출하여 logSyncDiagnostics/fetchSyncStatus 공용화 - hasEverHadUserCollection 메모리 캐싱 (매 호출 UserDefaults 읽기 제거) - RelativeDateTimeFormatter를 DateFormatters.syncRelativeDate로 캐싱
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 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.
문제
기존 유저로부터 앱 업데이트 후 데이터가 반복적으로 초기화된다는 피드백 접수.
근본 원인
앱 업데이트 / iCloud 재로그인 시
NSPersistentCloudKitContainer가 CloudKit 미러를 재구성하면서 로컬 UC가 일시적으로 0개가 되는 구간이 발생. 이때getUserCollection()이 빈 UC를 자동 생성하고, 이 빈 UC가 CloudKit에 Export되면서 기존 클라우드 데이터가 오염됨.sequenceDiagram participant App participant CoreData as CoreData (Local) participant CloudKit as CloudKit (Server) Note over App: 앱 업데이트 후 실행 App->>CoreData: getUserCollection() CoreData-->>App: UC 0개 (미러 재구성 중) rect rgb(255,230,230) Note over App: ❌ 기존 동작 (데이터 유실) App->>CoreData: 빈 UC 생성 CoreData->>CloudKit: Export 빈 UC Note over CloudKit: 기존 데이터 오염 end해결
1. 기존 유저 플래그 도입 (
hasEverHadUserCollection) — P0flowchart TD A[getUserCollection 호출] --> B{UC 존재?} B -->|Yes| C[✅ 반환 + 플래그 true 기록] B -->|No| D{억제 조건 체크} D -->|import/syncReset/gracePeriod| E[🛡️ .notFound throw] D -->|hasEverHadUserCollection=true| F[🛡️ .notFound throw<br/>빈 UC 생성 차단] D -->|모두 false + 신규유저| G[새 UC 생성] style F fill:#ffe0e0 style E fill:#ffe0e0 style G fill:#e0ffe0UserDefaults기반hasEverHadUserCollection플래그true기록clearHasEverHadUserCollection()으로 리셋하여 정상 동작 보장2. DailyTask 기본값 자동 생성 보호 — P0
isImportInProgress만 체크shouldSuppressDataCreation통합 프로퍼티로 교체 (import/syncReset/gracePeriod 모두 체크)3. Grace Period 연장 (30s → 120s) — P0
대용량 데이터의 CloudKit re-import 시간을 충분히 확보.
4. 동기화 상태 표시 — P1
유저 요청사항:
설정 화면에 iCloud 동기화 상태를 한 줄로 표시:
동기화 중...3분 전 동기화 · 152개 저장됨iCloud 데이터 대기 중...5. 에러 로깅 강화 — P1
모든 Storage 클래스의
debugPrint(error)→os_log(.error)교체.Release 빌드에서도 Console.app으로 프로덕션 에러 추적 가능.
변경 파일
CoreDataStorage.swifthasEverHadUserCollection,shouldSuppressDataCreation,SyncStatusInfo,fetchSyncStatus(), grace period 120s, 동기화 시각 추적CoreDataDailyTaskStorage.swiftshouldSuppressDataCreation적용CoreDataUserInfoStorage.swiftclearHasEverHadUserCollection()호출AppSettingReactor.swiftloadSyncStatusAction/Mutation 추가AppSettingView.swiftLocalizable.strings(ko/en)debugPrint→os_log교체icloud-sync.md시나리오 검증
Test Plan