Skip to content

fix(one_d4): delete occurrences before re-inserting in flushBatch#1145

Merged
aaylward merged 1 commit intomainfrom
fix/occurrence-duplication-on-reindex
Apr 10, 2026
Merged

fix(one_d4): delete occurrences before re-inserting in flushBatch#1145
aaylward merged 1 commit intomainfrom
fix/occurrence-duplication-on-reindex

Conversation

@aaylward
Copy link
Copy Markdown
Collaborator

@aaylward aaylward commented Apr 8, 2026

Summary

  • Re-indexing a partial month accumulated duplicate motif_occurrences rows for previously-indexed games: insertOccurrencesBatch used a plain INSERT with no conflict protection, and the ON DELETE CASCADE on game_features never fired because the upsert updates the row rather than deleting it
  • Fix: flushBatch now calls deleteOccurrencesByGameUrls before insertOccurrencesBatch, mirroring what the admin /reanalyze endpoint already did correctly
  • Adds a regression test verifying that delete-then-reinsert produces exactly one occurrence row, not two

Test plan

  • bazel test //domains/games/apis/one_d4/... — 35/35 pass
  • New test deleteOccurrencesByGameUrls_thenReinsert_doesNotDuplicate in GameFeatureDaoTest covers the regression

Re-indexing a partial month would accumulate duplicate motif_occurrences
rows for previously-indexed games because insertOccurrencesBatch used a
plain INSERT with no conflict protection. The fix mirrors what the admin
reanalyze endpoint already did correctly: delete existing occurrences for
each game_url before inserting fresh ones.

Adds a regression test that verifies delete-then-reinsert produces exactly
one occurrence row, not two.
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages bot commented Apr 8, 2026

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
1d4-web 4740992 Commit Preview URL

Branch Preview URL
Apr 08 2026, 04:59 AM

@aaylward aaylward merged commit 1428cf8 into main Apr 10, 2026
12 checks passed
@aaylward aaylward deleted the fix/occurrence-duplication-on-reindex branch April 10, 2026 22:26
@aaylward aaylward linked an issue Apr 11, 2026 that may be closed by this pull request
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.

one_d4: duplicate motif_occurrences rows on re-index

1 participant