Skip to content

perf(worker): Optimize flake processing by pre-fetching testruns#797

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

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

Conversation

@sentry
Copy link
Copy Markdown
Contributor

@sentry sentry bot commented Apr 14, 2026

Fixes WORKER-Y73. The issue was that: ProcessFlakesTask's N+1 queries for testruns and flags per upload cause hard_timeout.

  • Introduced a new function get_testruns_for_uploads to efficiently fetch testruns for multiple uploads in a single query.
  • Modified process_single_upload to accept an optional list of pre-fetched testruns, avoiding redundant database calls.
  • Updated process_flakes_for_commit to utilize the new batched fetching mechanism, significantly reducing the number of database queries when processing flakes for a commit with multiple uploads.

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

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
Changes flake-processing data access patterns by batching Testrun queries across uploads; behavior should be equivalent but mistakes in grouping/empty-upload handling could impact which testruns get processed or updated.

Overview
Optimizes process_flakes_for_commit flake detection by prefetching all recent Testruns for the commit’s uploads in a single query and grouping them per upload, instead of querying per upload.

Updates process_single_upload to accept an optional pre-fetched testruns list (falling back to the old per-upload query), and passes the grouped results through to avoid N+1 DB calls and reduce worker timeouts.

Reviewed by Cursor Bugbot for commit 836a08d. Bugbot is set up for automated code reviews on this repo. Configure here.

@sentry
Copy link
Copy Markdown
Contributor Author

sentry bot commented Apr 14, 2026

Codecov Report

❌ Patch coverage is 92.30769% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 92.25%. Comparing base (8c332b1) to head (836a08d).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...orker/services/test_analytics/ta_process_flakes.py 92.30% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #797      +/-   ##
==========================================
- Coverage   92.25%   92.25%   -0.01%     
==========================================
  Files        1306     1306              
  Lines       48004    48014      +10     
  Branches     1636     1636              
==========================================
+ Hits        44286    44293       +7     
- Misses       3407     3410       +3     
  Partials      311      311              
Flag Coverage Δ
workerintegration 58.55% <7.69%> (-0.04%) ⬇️
workerunit 90.37% <92.30%> (-0.02%) ⬇️

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 14, 2026

Codecov Report

❌ Patch coverage is 92.30769% with 1 line in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...orker/services/test_analytics/ta_process_flakes.py 92.30% 1 Missing ⚠️

📢 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