Skip to content

fix(worker): Resolve N+1 query in ProcessFlakesTask#975

Draft
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/worker-process-flakes-n-plus-1-vDaZYW
Draft

fix(worker): Resolve N+1 query in ProcessFlakesTask#975
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/worker-process-flakes-n-plus-1-vDaZYW

Conversation

@sentry
Copy link
Copy Markdown
Contributor

@sentry sentry Bot commented Jun 3, 2026

This PR addresses an N+1 query performance issue within the app.tasks.flakes.ProcessFlakesTask by refactoring the flake processing logic.

Changes Made:

  • Introduced get_testruns_for_uploads to fetch all relevant Testrun objects for a batch of uploads in a single database query, replacing individual queries per upload.
  • Modified handle_pass to collect expired Flake objects into a list, deferring their updates to a single Flake.objects.bulk_update call after processing all uploads.
  • Consolidated the Testrun.objects.bulk_update calls from within the per-upload loop into a single bulk_update operation at the end of process_flakes_for_commit.

These changes significantly reduce the number of database queries executed during flake processing, improving overall task efficiency and reducing database load.

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-YP4

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