mirror of
https://github.com/blakeblackshear/frigate.git
synced 2024-11-26 19:06:11 +01:00
cleanup missing files from database once per hour
This commit is contained in:
parent
07ad2d97b1
commit
6832575643
@ -413,6 +413,32 @@ class RecordingCleanup(threading.Thread):
|
|||||||
|
|
||||||
logger.debug("End expire files (legacy).")
|
logger.debug("End expire files (legacy).")
|
||||||
|
|
||||||
|
def sync_recordings(self):
|
||||||
|
logger.debug("Start sync recordings.")
|
||||||
|
|
||||||
|
# get all recordings in the db
|
||||||
|
recordings: Recordings = Recordings.select()
|
||||||
|
|
||||||
|
# get all recordings files on disk
|
||||||
|
process = sp.run(
|
||||||
|
["find", RECORD_DIR, "-type", "f"],
|
||||||
|
capture_output=True,
|
||||||
|
text=True,
|
||||||
|
)
|
||||||
|
files_on_disk = process.stdout.splitlines()
|
||||||
|
|
||||||
|
recordings_to_delete = []
|
||||||
|
for recording in recordings.objects().iterator():
|
||||||
|
if not recording.path in files_on_disk:
|
||||||
|
recordings_to_delete.append(recording.id)
|
||||||
|
|
||||||
|
logger.debug(
|
||||||
|
f"Deleting {len(recordings_to_delete)} recordings with missing files"
|
||||||
|
)
|
||||||
|
Recordings.delete().where(Recordings.id << recordings_to_delete).execute()
|
||||||
|
|
||||||
|
logger.debug("End sync recordings.")
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
# Expire recordings every minute, clean directories every hour.
|
# Expire recordings every minute, clean directories every hour.
|
||||||
for counter in itertools.cycle(range(60)):
|
for counter in itertools.cycle(range(60)):
|
||||||
@ -426,3 +452,4 @@ class RecordingCleanup(threading.Thread):
|
|||||||
if counter == 0:
|
if counter == 0:
|
||||||
self.expire_files()
|
self.expire_files()
|
||||||
remove_empty_directories(RECORD_DIR)
|
remove_empty_directories(RECORD_DIR)
|
||||||
|
self.sync_recordings()
|
||||||
|
Loading…
Reference in New Issue
Block a user