Skip to content

perf(daily): collapse Sudoku week-window to one day-bucketed query (mirror #915) - #924

Merged
wei18 merged 1 commit into
mainfrom
perf/921-sudoku-week-window-single-query
Jul 21, 2026
Merged

wei18 merged 1 commit into
mainfrom
perf/921-sudoku-week-window-single-query

Conversation

@wei18

@wei18 wei18 commented Jul 21, 2026

Copy link
Copy Markdown
Owner

What

Mirrors #915/#919 onto Sudoku. Sudoku's Daily week-window issued 7 per-day CloudKit queries; new PersistenceProtocol.fetchCompletedDailyIdsByDay() + gateway case .dailyCompletedAll (mode==daily AND status==completed, no puzzleId prefix) runs one query and buckets by extractDailyDay. fetchWeekWindow calls it once. All 18 protocol conformers updated.

Why

#757 wave-6 mirror-drift finding — MS got the single-query optimization (#915), Sudoku didn't.

Verification

  • PersistenceKit 79 + SudokuKit Daily 89 + GameCenterKit 69 + GameAppKit 46 pass; swiftlint --strict clean.
  • Key-format equivalence (the load-bearing invariant): bucket key extractDailyDay = puzzleId.prefix(10) and lookup key UTCDay.string(from:) both emit YYYY-MM-DD — byte-identical, and identical to the dayPrefix the old .dailyCompletedOn predicate filtered on. Directly verified by CR + Leader.
  • Snapshot baselines byte-unchanged: fixtures now script completedDailyIdsByDate across all 7 window days to reproduce the committed full-streak PNGs — NOT re-recorded (git status shows zero __Snapshots__ changes).
  • Dual CR: APPROVE — a round-1 REJECT was a can't-see-the-impl verification gate on the day-key formats; resolved by confirming both emit YYYY-MM-DD (three-way: two reviewers + passing snapshot/behavioral tests).

Closes #921

🤖 Generated with Claude Code

…irror #915)

#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]>
@wei18
wei18 enabled auto-merge (squash) July 21, 2026 05:55
@wei18
wei18 merged commit 20208a2 into main Jul 21, 2026
5 checks passed
@wei18
wei18 deleted the perf/921-sudoku-week-window-single-query branch July 21, 2026 05:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf(daily): mirror #915's single-query week-window onto Sudoku (still 7 CK reads)

1 participant