Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup timeline entries when relevant recording segments are removed #6319

Merged
merged 3 commits into from Apr 30, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 17 additions & 1 deletion frigate/record/cleanup.py
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 @@ -95,6 +95,14 @@ def expire_recordings(self) -> None:
.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
Expand Down Expand Up @@ -140,6 +148,14 @@ 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
for time in [
NickM-27 marked this conversation as resolved.
Show resolved Hide resolved
t
for t in timeline
if recording.start_time < t.timestamp < recording.end_time
]:
Timeline.delete().where(Timeline.timestamp == time.timestamp)

logger.debug(f"Expiring {len(deleted_recordings)} recordings")
# delete up to 100,000 at a time
max_deletes = 100000
Expand Down