From e30ff66f69e1193016eec61ce9767f0db6f0314c Mon Sep 17 00:00:00 2001 From: Nick Mowen Date: Sat, 29 Apr 2023 13:15:10 -0600 Subject: [PATCH] Make timeline cleanup simpler --- frigate/record/cleanup.py | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/frigate/record/cleanup.py b/frigate/record/cleanup.py index 4450fe8c7..1b1b52c19 100644 --- a/frigate/record/cleanup.py +++ b/frigate/record/cleanup.py @@ -95,14 +95,6 @@ class RecordingCleanup(threading.Thread): .objects() ) - timeline: Timeline = ( - Timeline.select(Timeline.timestamp) - .where(Timeline.camera == camera, Timeline.timestamp < expire_date) - .order_by(Timeline.timestamp) - .objects() - .iterator() - ) - # loop over recordings and see if they overlap with any non-expired events # TODO: expire segments based on segment stats according to config event_start = 0 @@ -149,12 +141,11 @@ class RecordingCleanup(threading.Thread): deleted_recordings.add(recording.id) # delete timeline entries relevant to this recording segment - for time in [ - t - for t in timeline - if recording.start_time < t.timestamp < recording.end_time - ]: - Timeline.delete().where(Timeline.timestamp == time.timestamp) + Timeline.delete( + Timeline.timestamp.between(recording.start_time, recording.end_time), + Timeline.timestamp < expire_date, + Timeline.camera == camera, + ).execute() logger.debug(f"Expiring {len(deleted_recordings)} recordings") # delete up to 100,000 at a time