|
@@ -3,7 +3,7 @@ from __future__ import annotations
|
|
|
from collections.abc import Callable, Mapping
|
|
|
from typing import Any
|
|
|
|
|
|
-from django.db.models import QuerySet
|
|
|
+from django.db.models import Q, QuerySet
|
|
|
|
|
|
from sentry.api.serializers import SentryAppAlertRuleActionSerializer, Serializer, serialize
|
|
|
from sentry.constants import SentryAppInstallationStatus, SentryAppStatus
|
|
@@ -203,14 +203,15 @@ class DatabaseBackedAppService(AppService):
|
|
|
# the installation by token id in SentryAppInstallation, we also search
|
|
|
# SentryAppInstallationToken by token id, then fetch the linked installation.
|
|
|
# Internal Integrations follow this pattern because they can have multiple tokens.
|
|
|
- from django.db.models import Q, Subquery
|
|
|
|
|
|
- subquery = SentryAppInstallationToken.objects.filter(
|
|
|
+ # Decompose this query instead of using a subquery for performance.
|
|
|
+ install_token_list = SentryAppInstallationToken.objects.filter(
|
|
|
api_token_id=filters["api_installation_token_id"],
|
|
|
- ).values("sentry_app_installation_id")
|
|
|
+ ).values_list("sentry_app_installation_id", flat=True)
|
|
|
+
|
|
|
query = query.filter(
|
|
|
Q(api_token_id=filters["api_installation_token_id"])
|
|
|
- | Q(id__in=Subquery(subquery))
|
|
|
+ | Q(id__in=list(install_token_list))
|
|
|
)
|
|
|
|
|
|
return query
|