Skip to content

Delete integration events in batches, keep 30 days - #1147

Closed
tudddorrr wants to merge 1 commit into
developfrom
talo-chunked-event-cleanup
Closed

tudddorrr wants to merge 1 commit into
developfrom
talo-chunked-event-cleanup

Conversation

@tudddorrr

Copy link
Copy Markdown
Collaborator

Why

cleanupIntegrationEvents deleted every expired row in a single nativeDelete per table. On google_play_games_integration_event (1.1M rows, 1.4 GB, about 18k rows and 18 MB a day) that statement ran 10 to 27 s. The server runs sync_binlog=1 and innodb_flush_log_at_trx_commit=1, so its one large commit stalls every other commit while it flushes.

What

  • Delete in batches of 1,000 rows (BATCH_SIZE), looping until a batch returns fewer rows than the limit, so no transaction is large.
  • Each batch selects the oldest ids (ordered by id) and deletes by id.
  • Retention drops from 60 days to 30 days (RETENTION_DAYS).
  • Targets, the console.info summary line and its counts are unchanged. Tables are now cleaned one after another instead of in parallel, so their commits do not overlap.

Test

should keep deleting while batches are full and keep 30 days inserts BATCH_SIZE + 1 events aged 31 days plus one aged 29 days, then asserts only the 29-day event survives. Reverting the loop to a single batch makes it fail.

pnpm test tests/tasks/cleanupIntegrationEvents.test.ts, pnpm lint, pnpm fmt and tsc --noEmit pass.

@codecov

codecov Bot commented Dec 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.87%. Comparing base (fe7d065) to head (0cddade).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1147      +/-   ##
===========================================
+ Coverage    98.86%   98.87%   +0.01%     
===========================================
  Files          548      548              
  Lines         8601     8612      +11     
  Branches      1156     1158       +2     
===========================================
+ Hits          8503     8515      +12     
  Misses          36       36              
+ Partials        62       61       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@tudddorrr tudddorrr closed this Dec 2, 2026
@tudddorrr
tudddorrr deleted the talo-chunked-event-cleanup branch December 2, 2026 12:53
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.

1 participant