S7: Alert check O(n*m) loop over all signals per alert #12
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Code Smell
File:
web/app/api/alerts/check/route.tsThe alert check endpoint has O(n*m) performance: for each active alert (n), it iterates over ALL latest signal values (m). With 50 alerts and 5000 latest signal rows, thats 250k iterations.
Code reference
Why it matters
The regex test (
RegExp.test) and optionalresolveNamecall inside the inner loop adds up. For regex alerts, the pattern is recompiled on every iteration (currently fine because its in the outer loop, but still heavy).Suggestion
Pre-build a map keyed by item_key for exact-match alerts. For regex alerts, pre-compile the pattern. Consider partitioning the loop: exact matches first via direct map lookup, then regex matches.
Note
This code was flagged as low priority. The
latestMapis typically small (< 100 entries) and alerts are < 20.