Skip to content

perf(workflows): Batch Action fetching in WorkflowEngineRuleSerializer#111945

Merged
kcons merged 3 commits into
masterfrom
kcons/nowacts
Mar 31, 2026
Merged

perf(workflows): Batch Action fetching in WorkflowEngineRuleSerializer#111945
kcons merged 3 commits into
masterfrom
kcons/nowacts

Conversation

@kcons
Copy link
Copy Markdown
Member

@kcons kcons commented Mar 31, 2026

Fixes SENTRY-5MD5.

@kcons kcons requested a review from a team as a code owner March 31, 2026 20:42
@kcons kcons requested a review from ceorourke March 31, 2026 20:42
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Mar 31, 2026
Comment thread src/sentry/api/serializers/models/rule.py
Copy link
Copy Markdown
Contributor

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Comment thread src/sentry/api/serializers/models/rule.py Outdated
@kcons kcons marked this pull request as draft March 31, 2026 20:56
Comment thread src/sentry/api/serializers/models/rule.py Outdated
Copy link
Copy Markdown
Contributor

@saponifi3d saponifi3d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm - might be also nice to include a test to illustrate the reduction in queries and prevent it from going back up.

Comment on lines +465 to +470
.exclude(
action__status__in=[
ObjectStatus.DELETION_IN_PROGRESS,
ObjectStatus.PENDING_DELETION,
],
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for a future PR... should we update the DataConditionGroupAction (and probably most of the models) to have a manager that will not the pending / deleted objects? (I think we did this for some of the models, but can't remember).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea. I'll do that.

@kcons kcons marked this pull request as ready for review March 31, 2026 21:21
@kcons
Copy link
Copy Markdown
Member Author

kcons commented Mar 31, 2026

I feel ok about not adding a query counting test here, just because it is a design bug when we do O(N) queries in get_attr (or serialize) anyway, so it does require a human mistake (or strategic choice) to cause this sort of problem, and we have detectors that flag N+1s (this one was flagged), so the risk of doing it accidentally and not noticing isn't huge. But also, query counting tests can be a bit brittle. This is maybe the 4th N+1 querying pattern I've fixed here this week, though, so maybe there's something to be said for trying to have serializer tests that count queries for N items, then N*2, and check that the query count hasn't gone up significantly..

Added ISWF-2360 to track.

@kcons kcons merged commit 2a005ec into master Mar 31, 2026
63 of 64 checks passed
@kcons kcons deleted the kcons/nowacts branch March 31, 2026 21:35
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 16, 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.

2 participants