Skip to content

fix(performance): Resolve N+1 queries in ProcessFlakesTask#1032

Open
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/worker-yq8-n1-flakes
Open

fix(performance): Resolve N+1 queries in ProcessFlakesTask#1032
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/worker-yq8-n1-flakes

Conversation

@sentry
Copy link
Copy Markdown
Contributor

@sentry sentry Bot commented Jun 7, 2026

This PR addresses an N+1 query issue identified in app.tasks.flakes.ProcessFlakesTask.

Changes Made:

  • Bulk fetching of Testruns: Previously, process_single_upload would execute a separate database query to fetch Testrun objects for each ReportSession (upload). This has been refactored to fetch all relevant Testrun objects for all uploads in a single query, then group them in memory.
  • Batch updating expiring Flakes: The handle_pass function previously called flake.save() individually for each flake that reached its expiration criteria (30 recent passes). This has been changed to collect all such expiring flakes and perform a single Flake.objects.bulk_update operation at the end of process_flakes_for_commit.

Why these changes?
These changes eliminate two N+1 query patterns, significantly reducing the number of database calls and improving the performance of the ProcessFlakesTask, especially for repositories with many uploads or a high volume of expiring flakes.

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.

Fixes WORKER-YQ8

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