mirror of
https://github.com/blakeblackshear/frigate.git
synced 2024-11-21 19:07:46 +01:00
use find to reduce CPU usage for legacy expiration
This commit is contained in:
parent
334095252c
commit
26424488a5
@ -244,6 +244,8 @@ class RecordingCleanup(threading.Thread):
|
|||||||
|
|
||||||
def expire_files(self):
|
def expire_files(self):
|
||||||
logger.debug("Start expire files (legacy).")
|
logger.debug("Start expire files (legacy).")
|
||||||
|
|
||||||
|
shortest_retention = self.config.record.retain_days
|
||||||
default_expire = (
|
default_expire = (
|
||||||
datetime.datetime.now().timestamp()
|
datetime.datetime.now().timestamp()
|
||||||
- SECONDS_IN_DAY * self.config.record.retain_days
|
- SECONDS_IN_DAY * self.config.record.retain_days
|
||||||
@ -254,8 +256,19 @@ class RecordingCleanup(threading.Thread):
|
|||||||
datetime.datetime.now().timestamp()
|
datetime.datetime.now().timestamp()
|
||||||
- SECONDS_IN_DAY * camera.record.retain_days
|
- SECONDS_IN_DAY * camera.record.retain_days
|
||||||
)
|
)
|
||||||
|
if camera.record.retain_days < shortest_retention:
|
||||||
|
shortest_retention = camera.record.retain_days
|
||||||
|
|
||||||
for p in Path("/media/frigate/recordings").rglob("*.mp4"):
|
logger.debug(f"Shortest retention: {shortest_retention}")
|
||||||
|
process = sp.run(
|
||||||
|
["find", RECORD_DIR, "-type", "f", "-mtime", f"+{shortest_retention}"],
|
||||||
|
capture_output=True,
|
||||||
|
text=True,
|
||||||
|
)
|
||||||
|
files_to_check = process.stdout.splitlines()
|
||||||
|
|
||||||
|
for f in files_to_check:
|
||||||
|
p = Path(f)
|
||||||
# Ignore files that have a record in the recordings DB
|
# Ignore files that have a record in the recordings DB
|
||||||
if Recordings.select().where(Recordings.path == str(p)).count():
|
if Recordings.select().where(Recordings.path == str(p)).count():
|
||||||
continue
|
continue
|
||||||
@ -265,8 +278,8 @@ class RecordingCleanup(threading.Thread):
|
|||||||
logger.debug("End expire files (legacy).")
|
logger.debug("End expire files (legacy).")
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
# Expire recordings every minute, clean directories every 5 minutes.
|
# Expire recordings every minute, clean directories every hour.
|
||||||
for counter in itertools.cycle(range(5)):
|
for counter in itertools.cycle(range(60)):
|
||||||
if self.stop_event.wait(60):
|
if self.stop_event.wait(60):
|
||||||
logger.info(f"Exiting recording cleanup...")
|
logger.info(f"Exiting recording cleanup...")
|
||||||
break
|
break
|
||||||
|
Loading…
Reference in New Issue
Block a user