You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR refactors the fetch_appropriate_parent_for_commit function in apps/worker/services/repository.py to address an N+1 query issue.
Problem:
The original implementation performed up to two database queries for each BFS level of a commit's ancestor tree. For repositories with deep commit histories, this resulted in a large number of redundant database calls (e.g., ~60 queries per task invocation observed in WORKER-SM9), leading to significant performance overhead.
Solution:
The function now first traverses the entire in-memory ancestor tree to collect all relevant commit IDs.
A single batched database query is then executed to fetch the commitid, branch, and message status for all collected ancestor IDs.
An in-memory lookup map is created from the query results.
The logic for selecting the closest parent (with and without a message, including branch tie-breaking) is then replayed entirely in-memory using this map, preserving the original behavior.
This change drastically reduces the number of database queries from N+1 to a single query, improving the performance of the CommitUpdate task.
Legal Boilerplate
Look, I get it. The entity doing business as "Codecov" is owned by Harness, Inc. In 2026 Harness acquired Codecov and as a result Harness 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 Harness can use, modify, copy, and redistribute my contributions, under Harness's choice of terms.
This PR refactors fetch_appropriate_parent_for_commit in apps/worker/services/repository.py to eliminate an N+1 query, replacing per-BFS-level database queries with a single batched query and an in-memory replay of the closest-parent selection. The refactor is behaviorally equivalent to the original: BFS levels are collected in the same order, the single query fetches the same (commitid, branch, message) set filtered by repo and non-deleted, and the new _possibly_filter_out_branch_from_list mirrors _possibly_filter_out_branch (single-candidate short-circuit, then first branch match, else None). Message-existence semantics and the closest_parent_without_message fallback are preserved, and existing BFS-path tests continue to cover the changed code.
❌ Patch coverage is 92.85714% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.63%. Comparing base (17e0f08) to head (b658a30).
✅ All tests successful. No failed tests found.
Seer wants to keep iterating on this pull request to get CI passing, but the Sentry GitHub App installation is missing permissions it needs to read the failing checks and push a fix.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR refactors the
fetch_appropriate_parent_for_commitfunction inapps/worker/services/repository.pyto address an N+1 query issue.Problem:
The original implementation performed up to two database queries for each BFS level of a commit's ancestor tree. For repositories with deep commit histories, this resulted in a large number of redundant database calls (e.g., ~60 queries per task invocation observed in WORKER-SM9), leading to significant performance overhead.
Solution:
commitid,branch, andmessagestatus for all collected ancestor IDs.This change drastically reduces the number of database queries from N+1 to a single query, improving the performance of the
CommitUpdatetask.Legal Boilerplate
Look, I get it. The entity doing business as "Codecov" is owned by Harness, Inc. In 2026 Harness acquired Codecov and as a result Harness 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 Harness can use, modify, copy, and redistribute my contributions, under Harness's choice of terms.
Fixes WORKER-SM9
This PR was automatically generated by Sentry. You can adjust this setting at any time.