Skip to content

Commit 4fb67fb

Browse files
authored
chore(hybridcloud) Use a more efficient RPC call in ratelimiting (#76258)
Fetching an installation + sentryapp + apiapplication only to use the organization_id contributes to higher latency. If we use a tailor made RPC call we should have better response times as there are fewer queries and less data transferred.
1 parent 592f367 commit 4fb67fb

File tree

1 file changed

+3
-12
lines changed

1 file changed

+3
-12
lines changed

src/sentry/ratelimits/utils.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
from sentry import features
1212
from sentry.auth.services.auth import AuthenticatedToken
13-
from sentry.constants import SentryAppInstallationStatus
1413
from sentry.ratelimits.concurrent import ConcurrentRateLimiter
1514
from sentry.ratelimits.config import DEFAULT_RATE_LIMIT_CONFIG, RateLimitConfig
1615
from sentry.types.ratelimit import RateLimit, RateLimitCategory, RateLimitMeta, RateLimitType
@@ -136,22 +135,14 @@ def get_rate_limit_key(
136135
def get_organization_id_from_token(token_id: int) -> int | None:
137136
from sentry.sentry_apps.services.app import app_service
138137

139-
installations = app_service.get_many(
140-
filter={
141-
"status": SentryAppInstallationStatus.INSTALLED,
142-
"api_installation_token_id": token_id,
143-
}
144-
)
145-
146-
installation = installations[0] if installations else None
147-
138+
organization_id = app_service.get_installation_org_id_by_token_id(token_id=token_id)
148139
# Return None to avoid collisions caused by tokens not being associated with
149140
# a SentryAppInstallation. We fallback to IP address rate limiting in this case.
150-
if not installation:
141+
if not organization_id:
151142
logger.info("installation.not_found", extra={"token_id": token_id})
152143
return None
153144

154-
return installation.organization_id
145+
return organization_id
155146

156147

157148
def get_rate_limit_config(

0 commit comments

Comments
 (0)