perf(worker): Consolidate flake updates in test analytics#879
perf(worker): Consolidate flake updates in test analytics#879sentry[bot] wants to merge 1 commit intomainfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #879 +/- ##
=======================================
Coverage 92.26% 92.26%
=======================================
Files 1307 1307
Lines 48011 48011
Branches 1632 1632
=======================================
Hits 44295 44295
Misses 3407 3407
Partials 309 309
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 6fff16b. Configure here.
| update_conflicts=True, | ||
| unique_fields=["id"], | ||
| update_fields=["end_date", "count", "recent_passes_count", "fail_count"], | ||
| ) |
There was a problem hiding this comment.
Deferred bulk_create loses all flake data on mid-processing error
Medium Severity
Moving bulk_create to after the while loop means that if any exception occurs during processing (e.g., a DB error in Testrun.objects.bulk_update or get_relevant_uploads), ALL accumulated flake changes across ALL lpop batches are lost. Meanwhile, testrun outcomes are already persisted per-upload via bulk_update in process_single_upload, and commit IDs are already removed from Redis by lpop — so they won't be reprocessed. Previously, flakes were persisted after each commit, so only the failing commit's data was at risk. The sibling implementation in detect_flakes.py handles this correctly by calling bulk_create per iteration inside transaction.atomic().
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 6fff16b. Configure here.


Fixes WORKER-Y9A. The issue was that: Repeatedly fetching all repository flakes for each commit processed in a batch causes an N+1 query.
process_flakes_for_repoto fetch once per repository.process_flakes_for_committo accept and update a sharedcurr_flakesdictionary.Flakeobjects to occur once per repository after all commits are processed.This fix was generated by Seer in Sentry, triggered automatically. 👁️ Run ID: 13593210
Not quite right? Click here to continue debugging with Seer.
Legal Boilerplate
Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. In 2022 this entity acquired Codecov and as result Sentry is going to need some rights from me in order to utilize my contributions in this PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.
Note
Low Risk
Low risk performance refactor that mainly changes when/where flakes are fetched and bulk-written; primary concern is ensuring deferred
Flake.objects.bulk_createstill persists all intended updates after multi-commit processing.Overview
Reduces N+1 DB work in test-analytics flake processing by fetching
curr_flakesonce per repo inprocess_flakes_for_repoand passing the shared dict intoprocess_flakes_for_commitfor all commits in the batch.Defers the
Flake.objects.bulk_create(... update_conflicts=True ...)upsert to run once after all queued commits are processed, and forces commit uploads evaluation vialist(get_relevant_uploads(...))to support logging/iteration without re-querying.Reviewed by Cursor Bugbot for commit 6fff16b. Bugbot is set up for automated code reviews on this repo. Configure here.