Skip to content

perf(daily): collapse MS week-window's 7 identical CK queries into one day-bucketed query - #919

Merged
wei18 merged 1 commit into
mainfrom
perf/915-ms-week-window-single-query
Jul 20, 2026
Merged

wei18 merged 1 commit into
mainfrom
perf/915-ms-week-window-single-query

Conversation

@wei18

@wei18 wei18 commented Jul 20, 2026

Copy link
Copy Markdown
Owner

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, filtered day == today client-side). New MinesweeperSavedGameStore.fetchCompletedDailyIdsByDay() runs the query once and buckets record names by UTC day; fetchWeekWindow calls 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 BEGINSWITH predicate and are genuinely distinct (untouched).

Verification

  • MinesweeperKit 370 tests + swiftlint --strict clean.
  • New test asserts queryCount == 1 for 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).
  • Dual CR: APPROVE ×2 — day-key format equivalence confirmed (both sides use UTCDay's 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

…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
wei18 enabled auto-merge (squash) July 20, 2026 16:47
@wei18
wei18 merged commit 4c79309 into main Jul 20, 2026
5 checks passed
@wei18
wei18 deleted the perf/915-ms-week-window-single-query branch July 20, 2026 16:48
@github-actions github-actions Bot mentioned this pull request Jul 20, 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]>
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): dedupe the 7 identical CloudKit queries in MS week-window fetch (follow-up to #912)

1 participant