|
11 | 11 | from sentry.api.serializers import Serializer, register |
12 | 12 | from sentry.constants import ObjectStatus |
13 | 13 | from sentry.db.models.manager.base_query_set import BaseQuerySet |
| 14 | +from sentry.integrations.services.integration.model import RpcIntegration |
| 15 | +from sentry.integrations.services.integration.service import integration_service |
14 | 16 | from sentry.models.environment import Environment |
15 | 17 | from sentry.models.project import Project |
16 | 18 | from sentry.models.rule import NeglectedRule, Rule, RuleActivity, RuleActivityType |
@@ -591,6 +593,22 @@ def get_attrs(self, item_list: Sequence[Workflow], user, **kwargs): |
591 | 593 | ) |
592 | 594 | actions_by_dcg = self._fetch_actions_by_dcg(all_dcg_ids) |
593 | 595 |
|
| 596 | + # Batch-fetch integrations for all actions to avoid per-action RPC calls in render_label |
| 597 | + all_integration_ids: set[int] = set() |
| 598 | + for action_list in actions_by_dcg.values(): |
| 599 | + for action in action_list: |
| 600 | + if action.integration_id is not None: |
| 601 | + all_integration_ids.add(action.integration_id) |
| 602 | + |
| 603 | + integration_cache: dict[int, RpcIntegration] = {} |
| 604 | + if all_integration_ids and item_list: |
| 605 | + integrations = integration_service.get_integrations( |
| 606 | + integration_ids=list(all_integration_ids), |
| 607 | + organization_id=item_list[0].organization_id, |
| 608 | + status=ObjectStatus.ACTIVE, |
| 609 | + ) |
| 610 | + integration_cache = {i.id: i for i in integrations} |
| 611 | + |
594 | 612 | last_triggered_lookup: dict[int, datetime] = {} |
595 | 613 | if "lastTriggered" in self.expand: |
596 | 614 | last_triggered_lookup = self._fetch_workflow_last_triggered(item_list) |
@@ -667,7 +685,7 @@ def get_attrs(self, item_list: Sequence[Workflow], user, **kwargs): |
667 | 685 | continue |
668 | 686 |
|
669 | 687 | action_data["name"] = action_to_handler[action].render_label( |
670 | | - workflow.organization_id, action_data |
| 688 | + workflow.organization_id, action_data, integration_cache=integration_cache |
671 | 689 | ) |
672 | 690 | installation_uuid = action_data.get("sentryAppInstallationUuid") |
673 | 691 | install_context = None |
|
0 commit comments