mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-07 11:45:24 +03:00
Cleanup
This commit is contained in:
parent
de4c6e2760
commit
4d0b75497a
@ -52,6 +52,13 @@ def sync_recordings(limited: bool) -> None:
|
|||||||
if not os.path.exists(recording.path):
|
if not os.path.exists(recording.path):
|
||||||
recordings_to_delete.add(recording.id)
|
recordings_to_delete.add(recording.id)
|
||||||
|
|
||||||
|
if len(recordings_to_delete) == 0:
|
||||||
|
return True
|
||||||
|
|
||||||
|
logger.info(
|
||||||
|
f"Deleting {len(recordings_to_delete)} recording DB entries with missing files"
|
||||||
|
)
|
||||||
|
|
||||||
# convert back to list of dictionaries for insertion
|
# convert back to list of dictionaries for insertion
|
||||||
recordings_to_delete = [
|
recordings_to_delete = [
|
||||||
{"id": recording_id} for recording_id in recordings_to_delete
|
{"id": recording_id} for recording_id in recordings_to_delete
|
||||||
@ -63,10 +70,6 @@ def sync_recordings(limited: bool) -> None:
|
|||||||
)
|
)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
logger.debug(
|
|
||||||
f"Deleting {len(recordings_to_delete)} recording DB entries with missing files"
|
|
||||||
)
|
|
||||||
|
|
||||||
# create a temporary table for deletion
|
# create a temporary table for deletion
|
||||||
RecordingsToDelete.create_table(temporary=True)
|
RecordingsToDelete.create_table(temporary=True)
|
||||||
|
|
||||||
@ -94,15 +97,22 @@ def sync_recordings(limited: bool) -> None:
|
|||||||
if not Recordings.select().where(Recordings.path == file).exists():
|
if not Recordings.select().where(Recordings.path == file).exists():
|
||||||
files_to_delete.append(file)
|
files_to_delete.append(file)
|
||||||
|
|
||||||
|
if len(files_to_delete) == 0:
|
||||||
|
return True
|
||||||
|
|
||||||
|
logger.info(f"Deleting {len(files_to_delete)} recordings files that are missing DB entries.")
|
||||||
|
|
||||||
if float(len(files_to_delete)) / max(1, len(files_on_disk)) > 0.5:
|
if float(len(files_to_delete)) / max(1, len(files_on_disk)) > 0.5:
|
||||||
logger.debug(
|
logger.debug(
|
||||||
f"Deleting {(float(len(files_to_delete)) / len(files_on_disk)):2f}% of recordings DB entries, could be due to configuration error. Aborting..."
|
f"Deleting {(float(len(files_to_delete)) / len(files_on_disk)):2f}% of recordings DB entries, could be due to configuration error. Aborting..."
|
||||||
)
|
)
|
||||||
return
|
return False
|
||||||
|
|
||||||
for file in files_to_delete:
|
for file in files_to_delete:
|
||||||
os.unlink(file)
|
os.unlink(file)
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
logger.debug("Start sync recordings.")
|
logger.debug("Start sync recordings.")
|
||||||
|
|
||||||
# start checking on the hour 36 hours ago
|
# start checking on the hour 36 hours ago
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user