mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-05 02:35:22 +03:00
Cleanup timeline entries when relevant recording segments are removed
This commit is contained in:
parent
e451f44ced
commit
1871a7b0bb
@ -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__)
|
||||
@ -95,6 +95,14 @@ 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
|
||||
@ -140,6 +148,14 @@ class RecordingCleanup(threading.Thread):
|
||||
Path(recording.path).unlink(missing_ok=True)
|
||||
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)
|
||||
|
||||
logger.debug(f"Expiring {len(deleted_recordings)} recordings")
|
||||
# delete up to 100,000 at a time
|
||||
max_deletes = 100000
|
||||
|
||||
Loading…
Reference in New Issue
Block a user