Skip to content

Commit c80dc9c

Browse files
committed
PLG: Centralize SQL condition to skip forced-online devices in event inserts
1 parent 50be56c commit c80dc9c

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

server/scan/session_events.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
from messaging.in_app import update_unread_notifications_count
2121
from const import NULL_EQUIVALENTS_SQL
2222

23+
# Predicate used in every negative-event INSERT to skip forced-online devices.
24+
# Centralised here so all three event paths stay in sync.
25+
_SQL_NOT_FORCED_ONLINE = "LOWER(COALESCE(devForceStatus, '')) != 'online'"
26+
2327

2428
# Make sure log level is initialized correctly
2529
Logger(get_setting_value("LOG_LEVEL"))
@@ -179,7 +183,7 @@ def insert_events(db):
179183
WHERE devAlertDown != 0
180184
AND devCanSleep = 0
181185
AND devPresentLastScan = 1
182-
AND LOWER(COALESCE(devForceStatus, '')) != 'online'
186+
AND {_SQL_NOT_FORCED_ONLINE}
183187
AND NOT EXISTS (SELECT 1 FROM CurrentScan
184188
WHERE devMac = scanMac
185189
) """)
@@ -195,7 +199,7 @@ def insert_events(db):
195199
AND devCanSleep = 1
196200
AND devIsSleeping = 0
197201
AND devPresentLastScan = 0
198-
AND LOWER(COALESCE(devForceStatus, '')) != 'online'
202+
AND {_SQL_NOT_FORCED_ONLINE}
199203
AND NOT EXISTS (SELECT 1 FROM CurrentScan
200204
WHERE devMac = scanMac)
201205
AND NOT EXISTS (SELECT 1 FROM Events
@@ -231,7 +235,7 @@ def insert_events(db):
231235
FROM Devices
232236
WHERE devAlertDown = 0
233237
AND devPresentLastScan = 1
234-
AND LOWER(COALESCE(devForceStatus, '')) != 'online'
238+
AND {_SQL_NOT_FORCED_ONLINE}
235239
AND NOT EXISTS (SELECT 1 FROM CurrentScan
236240
WHERE devMac = scanMac
237241
) """)

0 commit comments

Comments
 (0)