Reduce database queries to necessary labels

This commit is contained in:
Nick Mowen 2023-09-10 09:02:50 -06:00
parent 5658e5a4cc
commit 3fa5a41b60
2 changed files with 9 additions and 3 deletions

View File

@ -83,7 +83,10 @@ class EventCleanup(threading.Thread):
datetime.datetime.now() - datetime.timedelta(days=expire_days) datetime.datetime.now() - datetime.timedelta(days=expire_days)
).timestamp() ).timestamp()
# grab all events after specific time # grab all events after specific time
expired_events = Event.select().where( expired_events = Event.select(
Event.id,
Event.camera,
).where(
Event.camera.not_in(self.camera_keys), Event.camera.not_in(self.camera_keys),
Event.start_time < expire_after, Event.start_time < expire_after,
Event.label == event.label, Event.label == event.label,

View File

@ -89,7 +89,10 @@ class RecordingCleanup(threading.Thread):
# Get all the events to check against # Get all the events to check against
events: Event = ( events: Event = (
Event.select() Event.select(
Event.start_time,
Event.end_time,
)
.where( .where(
Event.camera == camera, Event.camera == camera,
# need to ensure segments for all events starting # need to ensure segments for all events starting
@ -109,7 +112,7 @@ class RecordingCleanup(threading.Thread):
keep = False keep = False
# Now look for a reason to keep this recording segment # Now look for a reason to keep this recording segment
for idx in range(event_start, len(events)): for idx in range(event_start, len(events)):
event = events[idx] event: Event = events[idx]
# if the event starts in the future, stop checking events # if the event starts in the future, stop checking events
# and let this recording segment expire # and let this recording segment expire