Skip to content

Commit

Permalink
refactor: cleaner naming
Browse files Browse the repository at this point in the history
  • Loading branch information
Kiryous committed Nov 24, 2024
1 parent 07ddcd0 commit ce7e8ee
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
9 changes: 4 additions & 5 deletions keep/api/core/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -2616,7 +2616,7 @@ def get_presets(
return presets


def get_preset_by_name(tenant_id: str, preset_name: str) -> Preset:
def get_db_preset_by_name(tenant_id: str, preset_name: str) -> Preset | None:
with Session(engine) as session:
preset = session.exec(
select(Preset)
Expand All @@ -2625,7 +2625,7 @@ def get_preset_by_name(tenant_id: str, preset_name: str) -> Preset:
).first()
return preset

def get_all_presets(tenant_id: str) -> List[Preset]:
def get_db_presets(tenant_id: str) -> List[Preset]:
with Session(engine) as session:
presets = (
session.exec(select(Preset).where(Preset.tenant_id == tenant_id))
Expand All @@ -2634,9 +2634,8 @@ def get_all_presets(tenant_id: str) -> List[Preset]:
)
return presets

#
def get_db_and_static_presets_dtos(tenant_id: str) -> List[PresetDto]:
presets = get_all_presets(tenant_id)
def get_all_presets_dtos(tenant_id: str) -> List[PresetDto]:
presets = get_db_presets(tenant_id)
static_presets_dtos = list(STATIC_PRESETS.values())
return [PresetDto(**preset.to_dict()) for preset in presets] + static_presets_dtos

Expand Down
4 changes: 2 additions & 2 deletions keep/api/routes/preset.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from sqlmodel import Session, select

from keep.api.consts import PROVIDER_PULL_INTERVAL_DAYS, STATIC_PRESETS
from keep.api.core.db import get_preset_by_name as get_preset_by_name_db
from keep.api.core.db import get_db_preset_by_name
from keep.api.core.db import get_presets as get_presets_db
from keep.api.core.db import (
get_session,
Expand Down Expand Up @@ -448,7 +448,7 @@ def get_preset_alerts(
if preset_name in STATIC_PRESETS:
preset = STATIC_PRESETS[preset_name]
else:
preset = get_preset_by_name_db(tenant_id, preset_name)
preset = get_db_preset_by_name(tenant_id, preset_name)
# if preset does not exist
if not preset:
raise HTTPException(404, "Preset not found")
Expand Down
6 changes: 3 additions & 3 deletions keep/api/tasks/process_event_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
from keep.api.core.db import (
bulk_upsert_alert_fields,
get_alerts_by_fingerprint,
get_all_presets,
get_db_and_static_presets_dtos,
get_db_presets,
get_all_presets_dtos,
get_enrichment_with_session,
get_session_sync,
)
Expand Down Expand Up @@ -444,7 +444,7 @@ def __handle_formatted_events(
return

try:
presets = get_db_and_static_presets_dtos(tenant_id)
presets = get_all_presets_dtos(tenant_id)
rules_engine = RulesEngine(tenant_id=tenant_id)
presets_do_update = []
for preset_dto in presets:
Expand Down

0 comments on commit ce7e8ee

Please sign in to comment.