Skip to content

perf(worker): Optimize flake processing by bulk fetching testruns#830

Open
sentry[bot] wants to merge 1 commit intomainfrom
seer/perf/bulk-flake-processing-Hr6O1j
Open

perf(worker): Optimize flake processing by bulk fetching testruns#830
sentry[bot] wants to merge 1 commit intomainfrom
seer/perf/bulk-flake-processing-Hr6O1j

Conversation

@sentry
Copy link
Copy Markdown
Contributor

@sentry sentry bot commented Apr 16, 2026

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.

  • Refactored testrun fetching to retrieve all relevant testruns for multiple uploads in a single query.
  • Modified process_single_upload to accept pre-fetched testruns and return modified testruns.
  • Updated process_flakes_for_commit to perform a single bulk_update for all modified testruns across all uploads.
  • Reduced the number of database queries during test analytics flake processing.

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.outcome updates or larger-than-expected bulk updates, but logic is otherwise unchanged.

Overview
Optimizes test-analytics flake processing to avoid per-upload Testrun queries by fetching all recent testruns for the commit’s uploads in one query (get_all_testruns) and grouping them by upload_id.

Refactors process_single_upload to operate on pre-fetched testruns, and moves Testrun.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.

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ 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,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 0746c1e. Configure here.

@sentry
Copy link
Copy Markdown
Contributor Author

sentry bot commented Apr 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.25%. Comparing base (9eed0bb) to head (0746c1e).
✅ All tests successful. No failed tests found.

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           
Flag Coverage Δ
workerintegration 58.52% <12.50%> (-0.03%) ⬇️
workerunit 90.39% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@codecov-notifications
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

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.

0 participants