perf(worker): Optimize flake processing by batching testrun queries#880
perf(worker): Optimize flake processing by batching testrun queries#880sentry[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 834f4ba. Configure here.
| @sentry_sdk.trace | ||
| def process_single_upload( | ||
| upload: ReportSession, curr_flakes: dict[bytes, Flake], repo_id: int | ||
| upload_id: int, |
There was a problem hiding this comment.
Unused upload_id parameter in process_single_upload
Low Severity
The upload_id parameter added to process_single_upload is never referenced anywhere in the function body. It's passed in from process_flakes_for_commit at the call site but serves no purpose inside the function, making it dead code that may confuse future readers about its intended use.
Reviewed by Cursor Bugbot for commit 834f4ba. Configure here.
| @sentry_sdk.trace | ||
| def process_single_upload( | ||
| upload: ReportSession, curr_flakes: dict[bytes, Flake], repo_id: int | ||
| upload_id: int, |
There was a problem hiding this comment.
Bug: The upload_id parameter in the process_single_upload function is unused and can be removed.
Severity: LOW
Suggested Fix
Remove the upload_id parameter from the function definition of process_single_upload at line 84 and update the corresponding call site at lines 132-134 to no longer pass this argument.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: apps/worker/services/test_analytics/ta_process_flakes.py#L84
Potential issue: The function `process_single_upload` is defined with a parameter
`upload_id`. However, this parameter is not used anywhere within the function's body.
The value is passed correctly from the call site, but since it is not utilized, it
serves no functional purpose. This is a result of a refactoring that decoupled testrun
retrieval from processing, leaving the parameter as a vestige. While it does not cause
any runtime errors or incorrect behavior, it represents dead code that can be confusing
for future maintenance.
Did we get this right? 👍 / 👎 to inform future reviews.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #880 +/- ##
=======================================
Coverage 92.26% 92.26%
=======================================
Files 1307 1307
Lines 48011 48015 +4
Branches 1632 1632
=======================================
+ Hits 44295 44299 +4
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. |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |


Fixes WORKER-Y9B. The issue was that:
process_flakes_for_commitfetches testruns individually per upload, causing N+1 queries.get_testrunstoget_testruns_for_uploadsto allow fetching testruns for multiple upload IDs in a single database query.process_single_uploadto accept a pre-fetched list ofTestrunobjects, decoupling testrun retrieval from processing logic.process_flakes_for_committo fetch all relevant testruns for a commit's uploads in a single batch query, then group them by upload ID usingdefaultdict.process_single_uploadto reduce database query overhead.This fix was generated by Seer in Sentry, triggered automatically. 👁️ Run ID: 13598118
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
Moderate risk: changes the flake-processing query and iteration order by batching
Testrunfetches across uploads; mistakes in grouping or ordering could cause missed/incorrectoutcomeupdates for some uploads.Overview
Optimizes
process_flakes_for_commitby eliminating per-uploadTestrunqueries: it now fetches all recent testruns for the commit’s uploads in oneupload_id__inquery, groups them by upload, and passes the pre-fetched lists intoprocess_single_upload.Refactors helpers accordingly (
get_testruns_for_uploads,process_single_uploadsignature) and adjusts ordering toorder_by("upload_id", "timestamp")to keep per-upload processing stable while reducing DB load.Reviewed by Cursor Bugbot for commit 834f4ba. Bugbot is set up for automated code reviews on this repo. Configure here.