Skip to content

Commit

Permalink
refactor: load event mappings by event types to improve performance
Browse files Browse the repository at this point in the history
  • Loading branch information
atompie committed Mar 28, 2024
1 parent 22a8a35 commit 9d52b05
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion tracardi/service/storage/mysql/service/event_mapping_service.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
from typing import Tuple, Optional
from typing import Tuple, Optional, List

from tracardi.config import tracardi
from tracardi.domain.event_type_metadata import EventTypeMetadata
Expand Down Expand Up @@ -48,6 +48,24 @@ async def load_by_event_type(self, event_type: str, only_enabled: bool = True) -
order_by=EventMappingTable.name
)

async def load_by_event_types(self, event_types: List[str], only_enabled: bool = True) -> SelectResult:
if only_enabled:
where = where_tenant_and_mode_context(
EventMappingTable,
EventMappingTable.event_type.in_(event_types),
EventMappingTable.enabled == only_enabled
)
else:
where = where_tenant_and_mode_context(
EventMappingTable,
EventMappingTable.event_type.in_(event_types)
)

return await self._select_in_deployment_mode(EventMappingTable,
where=where,
order_by=EventMappingTable.name
)

async def load_by_event_type_id(self, event_type_id: str, only_enabled: bool = True) -> SelectResult:
if only_enabled:
where = where_tenant_and_mode_context(
Expand Down

0 comments on commit 9d52b05

Please sign in to comment.