Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions keep/api/core/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -1395,15 +1395,20 @@ def batch_enrich(
}

# Prepare bulk update for existing enrichments
to_update = []
to_create = []
audit_entries = []

for fingerprint in fingerprints:
existing = existing_enrichments.get(fingerprint)

if existing:
to_update.append(existing.id)
# AlertEnrichment exist, update and merge enrichments
new_enrichment_data = {**existing.enrichments, **enrichments}
stmt = (
update(AlertEnrichment)
.where(AlertEnrichment.id == existing.id)
.values(enrichments=new_enrichment_data)
)
session.execute(stmt)
else:
# For new entries
to_create.append(
Expand All @@ -1425,15 +1430,6 @@ def batch_enrich(
)
)

# Bulk update in a single query
if to_update:
stmt = (
update(AlertEnrichment)
.where(AlertEnrichment.id.in_(to_update))
.values(enrichments=enrichments)
)
session.execute(stmt)

# Bulk insert new enrichments
if to_create:
session.add_all(to_create)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "keep"
version = "0.47.1"
version = "0.47.2"
description = "Alerting. for developers, by developers."
authors = ["Keep Alerting LTD"]
packages = [{include = "keep"}]
Expand Down
Loading