From ca7790ff65c943f4f57585f5d9a03b699535af3b Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Sun, 30 Apr 2023 08:28:21 -0600 Subject: [PATCH] Cleanup timeline entries when relevant recording segments are removed (#6319) * Cleanup timeline entries when relevant recording segments are removed * Make timeline cleanup simpler * Formatting --- frigate/record/cleanup.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/frigate/record/cleanup.py b/frigate/record/cleanup.py index 74c7eadf2..d649a2d87 100644 --- a/frigate/record/cleanup.py +++ b/frigate/record/cleanup.py @@ -12,7 +12,7 @@ from multiprocessing.synchronize import Event as MpEvent from frigate.config import RetainModeEnum, FrigateConfig from frigate.const import RECORD_DIR, SECONDS_IN_DAY -from frigate.models import Event, Recordings +from frigate.models import Event, Recordings, Timeline from frigate.record.util import remove_empty_directories logger = logging.getLogger(__name__) @@ -140,6 +140,15 @@ class RecordingCleanup(threading.Thread): Path(recording.path).unlink(missing_ok=True) deleted_recordings.add(recording.id) + # delete timeline entries relevant to this recording segment + 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 max_deletes = 100000