Skip to content

Commit b50bd12

Browse files
scttcperclaude
andauthored
perf(ownership): Fetch only the latest assignment activity (#128144)
Autoassignment checked `if activity:` on the assignment history queryset, which loaded every ASSIGNED activity for the group just to read the newest one. Use `.first()` so it only fetches one row. Same query count, but it was returning about 78M rows/day in US for 38M executions, so roughly half of those rows go away, pretty small thing. Also adds `-id` as a tiebreaker, matching the smart assignment scoring query. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 0ded594 commit b50bd12

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

‎src/sentry/models/projectownership.py‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -342,11 +342,13 @@ def handle_auto_assignment(
342342

343343
logging_extra = {**logging_extra, **activity_details}
344344

345-
activity = Activity.objects.filter(
346-
group=group, type=ActivityType.ASSIGNED.value
347-
).order_by("-datetime")
348-
if activity:
349-
auto_assigned = activity[0].data.get("integration")
345+
latest_assignment = (
346+
Activity.objects.filter(group=group, type=ActivityType.ASSIGNED.value)
347+
.order_by("-datetime", "-id")
348+
.first()
349+
)
350+
if latest_assignment:
351+
auto_assigned = latest_assignment.data.get("integration")
350352
if not auto_assigned and not force_autoassign:
351353
return
352354

0 commit comments

Comments
 (0)