Cleanup timeline entries when relevant recording segments are removed (#6319)

* Cleanup timeline entries when relevant recording segments are removed

* Make timeline cleanup simpler

* Formatting
This commit is contained in:
Nicolas Mowen 2023-04-30 08:28:21 -06:00 committed by GitHub
parent 37360edbc1
commit ca7790ff65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,7 +12,7 @@ from multiprocessing.synchronize import Event as MpEvent
from frigate.config import RetainModeEnum, FrigateConfig from frigate.config import RetainModeEnum, FrigateConfig
from frigate.const import RECORD_DIR, SECONDS_IN_DAY 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 from frigate.record.util import remove_empty_directories
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -140,6 +140,15 @@ class RecordingCleanup(threading.Thread):
Path(recording.path).unlink(missing_ok=True) Path(recording.path).unlink(missing_ok=True)
deleted_recordings.add(recording.id) 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") logger.debug(f"Expiring {len(deleted_recordings)} recordings")
# delete up to 100,000 at a time # delete up to 100,000 at a time
max_deletes = 100000 max_deletes = 100000