Skip to content

perf(issues): Fix N+1 query on repository in get_sorted_code_mapping_configs#106466

Merged
scttcper merged 1 commit intomasterfrom
scttcper/fix-n-plus-1-query-code-mapping
Jan 17, 2026
Merged

perf(issues): Fix N+1 query on repository in get_sorted_code_mapping_configs#106466
scttcper merged 1 commit intomasterfrom
scttcper/fix-n-plus-1-query-code-mapping

Conversation

@scttcper
Copy link
Member

Add select_related("repository") to the RepositoryProjectPathConfig query.

  • GroupAutofixEndpoint._get_legacy - iterates over code mappings and accesses mapping.repository.external_id
  • ProjectSeerPreferencesEndpoint.get - calls get_autofix_repos_from_project_code_mappings (seer/autofix/utils.py:319) which accesses code_mapping.repository.name, .provider, .external_id
  • ProjectStacktraceLinkEndpoint.get - calls get_stacktrace_config (integrations/utils/stacktrace_link.py:112) which accesses config.repository in the loop and passes it to get_link for install.get_stacktrace_link()
  • process_commit_context task - calls find_commit_context_for_event_all_frames → _generate_integration_to_files_mapping (integrations/utils/commit_context.py:255) which accesses code_mapping.repository

n+1 issues
https://sentry.sentry.io/issues/6218481153/
https://sentry.sentry.io/issues/6866977334/
https://sentry.sentry.io/issues/6834551736/

@scttcper scttcper requested a review from a team as a code owner January 16, 2026 20:36
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Jan 16, 2026
@scttcper scttcper enabled auto-merge (squash) January 16, 2026 20:50
…_configs

Add select_related("repository") to the RepositoryProjectPathConfig
query. The N+1 was triggered in GroupAutofixEndpoint._get_legacy which
iterates over code mappings and accesses mapping.repository.external_id.

Co-Authored-By: Claude <noreply@anthropic.com>
@scttcper scttcper force-pushed the scttcper/fix-n-plus-1-query-code-mapping branch from db67158 to 680423d Compare January 17, 2026 02:56
@scttcper scttcper merged commit ac94c29 into master Jan 17, 2026
65 checks passed
@scttcper scttcper deleted the scttcper/fix-n-plus-1-query-code-mapping branch January 17, 2026 03:17
BYK pushed a commit that referenced this pull request Jan 19, 2026
…configs (#106466)

Add select_related("repository") to the RepositoryProjectPathConfig
query.

- GroupAutofixEndpoint._get_legacy - iterates over code mappings and
accesses mapping.repository.external_id
- ProjectSeerPreferencesEndpoint.get - calls
get_autofix_repos_from_project_code_mappings (seer/autofix/utils.py:319)
which accesses code_mapping.repository.name, .provider, .external_id
- ProjectStacktraceLinkEndpoint.get - calls get_stacktrace_config
(integrations/utils/stacktrace_link.py:112) which accesses
config.repository in the loop and passes it to get_link for
install.get_stacktrace_link()
- process_commit_context task - calls
find_commit_context_for_event_all_frames →
_generate_integration_to_files_mapping
(integrations/utils/commit_context.py:255) which accesses
code_mapping.repository

n+1 issues  
https://sentry.sentry.io/issues/6218481153/
https://sentry.sentry.io/issues/6866977334/
https://sentry.sentry.io/issues/6834551736/

Co-authored-by: Claude <noreply@anthropic.com>
@github-actions github-actions bot locked and limited conversation to collaborators Feb 1, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants