Skip to content

Commit d84be0d

Browse files
authored
perf(aci): Avoid unnecessary organization db load (#99487)
Loading workflow.organization is convenient, but requires a db query in most current cases. We could annotate workflow to avoid it, but it's better practice to use fields from WorkflowEventData, which should basically never require a query once populated.
1 parent eef4afe commit d84be0d

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/sentry/workflow_engine/processors/workflow.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,10 @@ def evaluate_workflow_triggers(
225225
else:
226226
if evaluation:
227227
triggered_workflows.add(workflow)
228+
organization = event_data.group.project.organization
228229
if features.has(
229230
"organizations:workflow-engine-metric-alert-dual-processing-logs",
230-
workflow.organization,
231+
organization,
231232
):
232233
try:
233234
detector_workflow = DetectorWorkflow.objects.get(workflow_id=workflow.id)
@@ -236,7 +237,7 @@ def evaluate_workflow_triggers(
236237
extra={
237238
"workflow_id": workflow.id,
238239
"detector_id": detector_workflow.detector_id,
239-
"organization_id": workflow.organization.id,
240+
"organization_id": organization.id,
240241
"project_id": event_data.group.project.id,
241242
"group_type": event_data.group.type,
242243
},

tests/sentry/workflow_engine/processors/test_workflow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ def setUp(self) -> None:
352352
self.detector,
353353
self.detector_workflow,
354354
self.workflow_triggers,
355-
) = self.create_detector_and_workflow()
355+
) = self.create_detector_and_workflow(organization=self.organization)
356356

357357
occurrence = self.build_occurrence(evidence_data={"detector_id": self.detector.id})
358358
self.group, self.event, self.group_event = self.create_group_event(

0 commit comments

Comments
 (0)