Skip to content

perf(files): Add organization_id to artifact bundle lookup queries#114924

Closed
scttcper wants to merge 1 commit intomasterfrom
scttcper/fix-artifact-bundle-org-scope
Closed

perf(files): Add organization_id to artifact bundle lookup queries#114924
scttcper wants to merge 1 commit intomasterfrom
scttcper/fix-artifact-bundle-org-scope

Conversation

@scttcper
Copy link
Copy Markdown
Member

@scttcper scttcper commented May 5, 2026

Adds the redundant organization_id predicate to the outer ArtifactBundle query in get_artifact_bundles_containing_url and get_artifact_bundles_by_release. Without it Postgres has to scan the full table before evaluating the EXISTS subqueries. organization_id is already indexed (db_index=True) on ArtifactBundle so this should narrow the scan significantly.

artifact-lookup transaction summary

Before:

SELECT "sentry_artifactbundle"."id", "sentry_artifactbundle"."date_added"
FROM "sentry_artifactbundle"
WHERE (
  EXISTS(SELECT 1 FROM "sentry_artifactbundleindex" U0
    WHERE U0."artifact_bundle_id" = "sentry_artifactbundle"."id"
      AND U0."organization_id" = %s
      AND UPPER(U0."url"::text) LIKE UPPER(%s) LIMIT 1)
  AND EXISTS(SELECT 1 FROM "sentry_projectartifactbundle" U0
    WHERE U0."artifact_bundle_id" = "sentry_artifactbundle"."id"
      AND U0."project_id" = %s LIMIT 1)
  AND EXISTS(SELECT 1 FROM "sentry_releaseartifactbundle" U0
    WHERE U0."artifact_bundle_id" = "sentry_artifactbundle"."id"
      AND U0."dist_name" = %s
      AND U0."organization_id" = %s
      AND U0."release_name" = %s LIMIT 1)
)
ORDER BY "sentry_artifactbundle"."date_last_modified" DESC, 1 DESC
LIMIT 5

After:

SELECT "sentry_artifactbundle"."id", "sentry_artifactbundle"."date_added"
FROM "sentry_artifactbundle"
WHERE (
  EXISTS(SELECT 1 FROM "sentry_artifactbundleindex" U0
    WHERE U0."artifact_bundle_id" = "sentry_artifactbundle"."id"
      AND U0."organization_id" = %s
      AND UPPER(U0."url"::text) LIKE UPPER(%s) LIMIT 1)
  AND EXISTS(SELECT 1 FROM "sentry_projectartifactbundle" U0
    WHERE U0."artifact_bundle_id" = "sentry_artifactbundle"."id"
      AND U0."project_id" = %s LIMIT 1)
  AND EXISTS(SELECT 1 FROM "sentry_releaseartifactbundle" U0
    WHERE U0."artifact_bundle_id" = "sentry_artifactbundle"."id"
      AND U0."dist_name" = %s
      AND U0."organization_id" = %s
      AND U0."release_name" = %s LIMIT 1)
  AND "sentry_artifactbundle"."organization_id" = %s
)
ORDER BY "sentry_artifactbundle"."date_last_modified" DESC, 1 DESC
LIMIT 5

… queries

The artifact_lookup endpoint queries for bundles by URL and release
without filtering the outer ArtifactBundle table by org. Postgres has to
scan all bundles across all orgs before evaluating the EXISTS subqueries,
which gets slow for large tables.

Adds the redundant organization_id predicate to
get_artifact_bundles_containing_url and get_artifact_bundles_by_release
so the indexed org column narrows the scan up front.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label May 5, 2026
@scttcper scttcper changed the title perf(artifact-bundles): Add organization_id to artifact bundle lookup queries perf(files): Add organization_id to artifact bundle lookup queries May 5, 2026
@scttcper scttcper closed this May 5, 2026
@scttcper scttcper deleted the scttcper/fix-artifact-bundle-org-scope branch May 5, 2026 22:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant