Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.

Commit d9d856d

Browse files
Only send one server side event per request (#925)
We were sending one server side event per critical alert found. This should reduce the amount of server side events sent.
1 parent 5abdad6 commit d9d856d

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/codegate/db/connection.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,12 +251,18 @@ async def record_alerts(self, alerts: List[Alert], initial_id: Optional[str]) ->
251251
except Exception as e:
252252
logger.error(f"Failed to record alert: {alert}.", error=str(e))
253253

254+
critical_alert_timestamp = None
254255
recorded_alerts = []
255256
for alert_coro in alerts_tasks:
256257
alert_result = alert_coro.result()
257258
recorded_alerts.append(alert_result)
258259
if alert_result and alert_result.trigger_category == "critical":
259-
await alert_queue.put(f"New alert detected: {alert.timestamp}")
260+
critical_alert_timestamp = alert.timestamp
261+
262+
# only alert once per request and not once per critical alert.
263+
if critical_alert_timestamp:
264+
await alert_queue.put(f"New alert detected: {critical_alert_timestamp}")
265+
260266
# Uncomment to debug the recorded alerts
261267
# logger.debug(f"Recorded alerts: {recorded_alerts}")
262268
return recorded_alerts

0 commit comments

Comments
 (0)