Skip to content

perf(worker): Batch testrun fetching for flake processing#829

Open
sentry[bot] wants to merge 1 commit intomainfrom
seer/perf/batch-flake-testruns-hDw0xa
Open

perf(worker): Batch testrun fetching for flake processing#829
sentry[bot] wants to merge 1 commit intomainfrom
seer/perf/batch-flake-testruns-hDw0xa

Conversation

@sentry
Copy link
Copy Markdown
Contributor

@sentry sentry bot commented Apr 16, 2026

Fixes WORKER-Y7Y. The issue was that: The process_flakes_for_commit function executes a separate database query for testruns for each upload, causing an N+1 query pattern.

  • Modified get_testruns to accept a list of upload IDs, enabling batched fetching of testruns.
  • Updated process_flakes_for_commit to fetch all relevant testruns for a commit's uploads in a single database query.
  • Grouped fetched testruns by upload ID using defaultdict for efficient distribution to individual upload processing.
  • Passed pre-fetched and filtered testruns to process_single_upload to eliminate redundant database calls within the loop.
  • Improved performance by significantly reducing the number of database queries during test analytics flake processing.

This fix was generated by Seer in Sentry, triggered automatically. 👁️ Run ID: 13387071

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
Primarily a performance refactor that preserves existing flake/outcome logic, with low functional risk aside from potential edge cases in testrun grouping or increased memory use when materializing all results.

Overview
Optimizes flake processing to avoid an N+1 query pattern by fetching all recent Testruns for a commit’s uploads in a single query, grouping them by upload_id, and passing the pre-fetched list into process_single_upload.

This changes get_testruns to accept multiple upload IDs (returning a materialized list) and updates process_flakes_for_commit/process_single_upload call flow accordingly.

Reviewed by Cursor Bugbot for commit c2b07f2. 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 c2b07f2. Configure here.

@sentry_sdk.trace
def process_single_upload(
upload: ReportSession, curr_flakes: dict[bytes, Flake], repo_id: int
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 after refactoring

Low Severity

The upload parameter of process_single_upload is no longer referenced anywhere in the function body. Previously it was used to call get_testruns(upload), but now that testruns are passed in directly, upload became dead code. It's still passed at the call site but serves no purpose inside the function.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit c2b07f2. 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 (c2b07f2).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #829   +/-   ##
=======================================
  Coverage   92.25%   92.25%           
=======================================
  Files        1306     1306           
  Lines       48012    48016    +4     
  Branches     1636     1636           
=======================================
+ Hits        44294    44298    +4     
  Misses       3407     3407           
  Partials      311      311           
Flag Coverage Δ
workerintegration 58.53% <20.00%> (-0.01%) ⬇️
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-notifications bot commented Apr 16, 2026

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