Skip to content

Commit

Permalink
Cleanup timeline entries when relevant recording segments are removed (
Browse files Browse the repository at this point in the history
…#6319)

* Cleanup timeline entries when relevant recording segments are removed

* Make timeline cleanup simpler

* Formatting
  • Loading branch information
NickM-27 committed Apr 30, 2023
1 parent 37360ed commit ca7790f
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion frigate/record/cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

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__)
Expand Down Expand Up @@ -140,6 +140,15 @@ def expire_recordings(self) -> None:
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
Expand Down

0 comments on commit ca7790f

Please sign in to comment.