perf(worker): Optimize flake processing by bulk fetching testruns#830
perf(worker): Optimize flake processing by bulk fetching testruns#830sentry[bot] wants to merge 1 commit intomainfrom
Conversation
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 0746c1e. Configure here.
| ): | ||
| testruns = get_testruns(upload) | ||
|
|
||
| upload: ReportSession, |
There was a problem hiding this comment.
Unused upload parameter in process_single_upload
Low Severity
The upload parameter of process_single_upload is no longer used anywhere in the function body after the refactoring. It was previously needed to call get_testruns(upload), but now that testruns are passed in directly via the new testruns parameter, upload is dead code. The @sentry_sdk.trace decorator does not automatically capture function parameters either, so nothing consumes this value. This adds confusion about the function's interface and dependencies.
Reviewed by Cursor Bugbot for commit 0746c1e. Configure here.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #830 +/- ##
=======================================
Coverage 92.25% 92.25%
=======================================
Files 1306 1306
Lines 48012 48021 +9
Branches 1636 1636
=======================================
+ Hits 44294 44303 +9
Misses 3407 3407
Partials 311 311
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |


Fixes WORKER-Y7Z. The issue was that: N+1 queries for Testrun objects within a loop iterating over uploads, routed to replica DB, cause task hard timeout.
process_single_uploadto accept pre-fetched testruns and return modified testruns.process_flakes_for_committo perform a singlebulk_updatefor all modified testruns across all uploads.This fix was generated by Seer in Sentry, triggered automatically. 👁️ Run ID: 13391124
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
Medium Risk
Touches batch DB read/write behavior in the flake-processing worker; mistakes could cause missed or extra
Testrun.outcomeupdates or larger-than-expected bulk updates, but logic is otherwise unchanged.Overview
Optimizes test-analytics flake processing to avoid per-upload
Testrunqueries by fetching all recent testruns for the commit’s uploads in one query (get_all_testruns) and grouping them byupload_id.Refactors
process_single_uploadto operate on pre-fetched testruns, and movesTestrun.objects.bulk_update(..., ["outcome"])to a single commit-level update across all uploads after processing.Reviewed by Cursor Bugbot for commit 0746c1e. Bugbot is set up for automated code reviews on this repo. Configure here.