Repository navigation
perf(daily): collapse MS week-window's 7 identical CK queries into one day-bucketed query - #919
Merged
Merged
Conversation
…e day-bucketed query Follow-up to #912. MS's fetchWeekWindow issued 7 completed-id queries (one per window day), but MinesweeperSavedGameStore.fetchCompletedDailyIds(for:) runs a DATE-AGNOSTIC `.statusEquals(status:"completed")` query and filters day == today client-side — so the 7 calls were 7 byte-identical CloudKit reads. #912 parallelized them (fixed latency); this removes the redundancy. New MinesweeperSavedGameStore.fetchCompletedDailyIdsByDay() runs the query ONCE and buckets record names by UTC day (same summary → modeRaw==.daily → dailyDay filter chain, grouped instead of single-day-filtered). fetchWeekWindow calls it once and builds the 7 slots by day-string lookup (empty Set for a day with no completion), dropping the withThrowingTaskGroup fan-out — the stride(6...0) map is naturally ordered so the explicit re-sort is gone. Bootstrap CK reads: 8 → 2 (1 window + 1 failed). MS-only: Sudoku's fetchCompletedDailyIds carries a real per-day puzzleId predicate, so its per-day queries are genuinely distinct — untouched. The single-day fetchCompletedDailyIds(for:)/fetchFailedDailyIds(for:) are unchanged (their guard-view + today-failed callers need one day). Verified: MinesweeperKit 370 tests + swiftlint --strict clean. New test asserts queryCount==1 for a full window + records bucket to their OWN day only; stale query-count assertions updated (8→2, 16→4) to match. Dual CR: APPROVE x2 (day- key format equivalence confirmed both sides use UTCDay's YYYY-MM-DD, degrade + ordering preserved). Closes #915 Co-Authored-By: Claude Fable 5 <[email protected]>
wei18
enabled auto-merge (squash)
July 20, 2026 16:47
Closed
This was referenced Jul 21, 2026
wei18
added a commit
that referenced
this pull request
Jul 21, 2026
…irror #915) (#924) #757 wave-6. #915/#919 gave Minesweeper a single day-bucketed week-window query; Sudoku's fetchWeekWindow still fanned out 7 per-day CloudKit round- trips (mode==daily AND status==completed AND puzzleId BEGINSWITH <dayPrefix>). New PersistenceProtocol.fetchCompletedDailyIdsByDay() -> [String: Set<String>] backed by a new gateway case .dailyCompletedAll (mode==daily AND status== completed, no puzzleId prefix) runs ONE query and buckets record puzzleIds by SavedGameStore.extractDailyDay (the 10-char YYYY-MM-DD prefix). fetchWeekWindow calls it once and builds the 7 slots by day-string lookup (empty Set for an absent day), dropping the withThrowingTaskGroup fan-out — the stride(6...0) map is naturally ordered so the explicit re-sort is gone. All 18 protocol conformers (production + every test fake/stub) implement the new method. Key-format equivalence (CR-verified): the bucket key extractDailyDay = puzzleId.prefix(10) and the lookup key UTCDay.string(from:) both emit "%04d-%02d-%02d" — byte-identical, and identical to the dayPrefix the old .dailyCompletedOn predicate filtered on server-side, so per-day results are unchanged. Malformed/non-daily ids drop the same way (server BEGINSWITH miss vs client extractDailyDay==nil). Degrade (throw → report → nil whole strip) and single-day fetchCompletedDailyIds(for:) (AchievementEvaluator/MS guard) are untouched. Snapshot fixtures for snapshotEasyCompletedIPhoneLight/allCompleted were updated to script completedDailyIdsByDate across all 7 window days — NOT re-recorded; the committed baselines are byte-unchanged (the old fake's date-agnostic global default faked the full-streak visual; the fixture now supplies real per-day data reproducing it exactly). Verified: PersistenceKit 79 + SudokuKit Daily 89 (incl. both snapshots vs unchanged baselines + weekWindowFetchIssuesExactlyOneQuery) + GameCenterKit 69 + GameAppKit 46 all pass; swiftlint --strict clean. Dual CR: APPROVE (day- key equivalence + baseline-unmodified directly verified) — a round-1 REJECT was a can't-see-the-impl verification gate, resolved by confirming both keys emit YYYY-MM-DD. Closes #921 Co-authored-by: Claude Fable 5 <[email protected]>
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.
What
Follow-up to #912. MS's Daily week-window fetched completed ids with 7 identical, date-agnostic CloudKit queries (one per window day, each
.statusEquals(status:"completed")returning the full set, filteredday == todayclient-side). NewMinesweeperSavedGameStore.fetchCompletedDailyIdsByDay()runs the query once and buckets record names by UTC day;fetchWeekWindowcalls it once and builds the 7 slots by day-string lookup, dropping the task-group fan-out. Bootstrap CK reads: 8 → 2.Why
#912 parallelized the 7 calls (fixed latency) but they were still 7× the CloudKit read cost for data one query returns. MS-only — Sudoku's per-day queries carry a real
puzzleId BEGINSWITHpredicate and are genuinely distinct (untouched).Verification
swiftlint --strictclean.queryCount == 1for a full window and records bucket to their own day only; week-strip ordering [6..0] + empty-day fallback regressions hold; stale query-count assertions updated (8→2, 16→4).YYYY-MM-DD, an agreement that already had to hold pre-perf(daily): dedupe the 7 identical CloudKit queries in MS week-window fetch (follow-up to #912) #915), degrade + ordering preserved, single-day methods byte-unchanged.Closes #915
🤖 Generated with Claude Code