perf(worker): Optimize flake processing by batch fetching testruns#801
perf(worker): Optimize flake processing by batch fetching testruns#801sentry[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 01a2798. Configure here.
| ).order_by("timestamp") | ||
|
|
||
|
|
||
| def get_testruns_for_uploads(upload_ids: list[int]) -> dict[int, list[Testrun]]: |
There was a problem hiding this comment.
Dead function get_testruns left after refactoring
Low Severity
The get_testruns function in ta_process_flakes.py is now unused dead code. It was previously called by process_single_upload, but this refactoring replaced that call with the new batch-fetching get_testruns_for_uploads. No other file imports get_testruns from this module (the one in detect_flakes.py is a separate, locally-defined function). This dead function adds confusion about which function is canonical for fetching testruns.
Reviewed by Cursor Bugbot for commit 01a2798. Configure here.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #801 +/- ##
==========================================
- Coverage 92.25% 92.25% -0.01%
==========================================
Files 1306 1306
Lines 48004 48012 +8
Branches 1636 1636
==========================================
+ Hits 44286 44292 +6
- Misses 3407 3409 +2
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-Y77. The issue was that: N+1 queries occur because
get_relevant_uploadsdoesn't eager-loadReportSessionrelationships, leading to repeated database hits per upload.get_relevant_uploadsto eagerly load relatedreport,commit, andrepositoryobjects usingselect_related.get_testruns_for_uploadsto efficiently retrieve testruns for a list of upload IDs.process_single_uploadto accept pre-fetched testruns, decoupling data retrieval from processing logic.This fix was generated by Seer in Sentry, triggered automatically. 👁️ Run ID: 13287582
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 database query patterns and refactors
process_single_uploadto use pre-fetched testruns, which could affect which testruns are processed per upload if the grouping/filtering is wrong.Overview
Improves test flake processing performance by eliminating per-upload DB fetches.
get_relevant_uploadsnow usesselect_relatedto eager-loadreport/commit/repository, andprocess_flakes_for_commitbatch-fetches all recentTestruns for the commit’s uploads via newget_testruns_for_uploads, passing them intoprocess_single_uploadinstead of querying per upload.Reviewed by Cursor Bugbot for commit 01a2798. Bugbot is set up for automated code reviews on this repo. Configure here.