From 64f9c0e67fdc6fd19ac6a1de220c89d0c9c9b019 Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Mon, 26 Aug 2024 08:12:34 -0600 Subject: [PATCH] Update version and cleanup --- frigate/events/maintainer.py | 2 +- frigate/record/cleanup.py | 27 ++++++++++++++++----------- frigate/record/record.py | 4 ++-- frigate/test/test_config.py | 28 +++++++++++++++++++++------- frigate/util/config.py | 16 ++++++++-------- 5 files changed, 48 insertions(+), 29 deletions(-) diff --git a/frigate/events/maintainer.py b/frigate/events/maintainer.py index 2753300ef..6707bfb41 100644 --- a/frigate/events/maintainer.py +++ b/frigate/events/maintainer.py @@ -5,7 +5,7 @@ from multiprocessing.synchronize import Event as MpEvent from typing import Dict from frigate.comms.events_updater import EventEndPublisher, EventUpdateSubscriber -from frigate.config import EventsConfig, FrigateConfig +from frigate.config import FrigateConfig from frigate.events.types import EventStateEnum, EventTypeEnum from frigate.models import Event from frigate.util.builtin import to_relative_box diff --git a/frigate/record/cleanup.py b/frigate/record/cleanup.py index 1b41ea22a..9f00fb50e 100644 --- a/frigate/record/cleanup.py +++ b/frigate/record/cleanup.py @@ -69,22 +69,27 @@ class RecordingCleanup(threading.Thread): detection_expire_date = ( now - datetime.timedelta(days=config.record.detections.retain.days) ).timestamp() - expired_reviews: ReviewSegment = ReviewSegment.select(ReviewSegment.id).where( - ReviewSegment.camera == config.name - and ( - ( - ReviewSegment.severity == "alert" - and ReviewSegment.end_time < alert_expire_date - ) - or ( - ReviewSegment.severity == "detection" - and ReviewSegment.end_time < detection_expire_date + expired_reviews: ReviewSegment = ( + ReviewSegment.select(ReviewSegment.id) + .where( + ReviewSegment.camera == config.name + and ( + ( + ReviewSegment.severity == "alert" + and ReviewSegment.end_time < alert_expire_date + ) + or ( + ReviewSegment.severity == "detection" + and ReviewSegment.end_time < detection_expire_date + ) ) ) + .namedtuples() ) max_deletes = 100000 - deleted_reviews_list = list(expired_reviews) + deleted_reviews_list = list(map(lambda x: x[0], expired_reviews)) + logger.info(f"the list is {deleted_reviews_list}") for i in range(0, len(deleted_reviews_list), max_deletes): ReviewSegment.delete().where( ReviewSegment.id << deleted_reviews_list[i : i + max_deletes] diff --git a/frigate/record/record.py b/frigate/record/record.py index 98faa390c..00634f157 100644 --- a/frigate/record/record.py +++ b/frigate/record/record.py @@ -11,7 +11,7 @@ from playhouse.sqliteq import SqliteQueueDatabase from setproctitle import setproctitle from frigate.config import FrigateConfig -from frigate.models import Event, Recordings +from frigate.models import Recordings, ReviewSegment from frigate.record.maintainer import RecordingMaintainer from frigate.util.services import listen @@ -41,7 +41,7 @@ def manage_recordings(config: FrigateConfig) -> None: }, timeout=max(60, 10 * len([c for c in config.cameras.values() if c.enabled])), ) - models = [Event, Recordings] + models = [ReviewSegment, Recordings] db.bind(models) maintainer = RecordingMaintainer( diff --git a/frigate/test/test_config.py b/frigate/test/test_config.py index 7f35bf78e..c703de893 100644 --- a/frigate/test/test_config.py +++ b/frigate/test/test_config.py @@ -381,9 +381,7 @@ class TestConfig(unittest.TestCase): def test_motion_mask_relative_matches_explicit(self): config = { "mqtt": {"host": "mqtt"}, - "record": { - "events": {"retain": {"default": 20, "objects": {"person": 30}}} - }, + "record": {"alerts": {"retain": {"days": 20}}}, "cameras": { "explicit": { "ffmpeg": { @@ -581,7 +579,11 @@ class TestConfig(unittest.TestCase): config = { "mqtt": {"host": "mqtt"}, "record": { - "events": {"retain": {"default": 20, "objects": {"person": 30}}} + "alerts": { + "retain": { + "days": 20, + } + } }, "cameras": { "back": { @@ -605,7 +607,11 @@ class TestConfig(unittest.TestCase): config = { "mqtt": {"host": "mqtt"}, "record": { - "events": {"retain": {"default": 20, "objects": {"person": 30}}} + "alerts": { + "retain": { + "days": 20, + } + } }, "cameras": { "back": { @@ -629,7 +635,11 @@ class TestConfig(unittest.TestCase): config = { "mqtt": {"host": "mqtt"}, "record": { - "events": {"retain": {"default": 20, "objects": {"person": 30}}} + "alerts": { + "retain": { + "days": 20, + } + } }, "cameras": { "back": { @@ -660,7 +670,11 @@ class TestConfig(unittest.TestCase): config = { "mqtt": {"host": "mqtt"}, "record": { - "events": {"retain": {"default": 20, "objects": {"person": 30}}} + "alerts": { + "retain": { + "days": 20, + } + } }, "cameras": { "back": { diff --git a/frigate/util/config.py b/frigate/util/config.py index 24c533aa6..3f3919d47 100644 --- a/frigate/util/config.py +++ b/frigate/util/config.py @@ -13,7 +13,7 @@ from frigate.util.services import get_video_properties logger = logging.getLogger(__name__) -CURRENT_CONFIG_VERSION = "0.14.1-0" +CURRENT_CONFIG_VERSION = "0.15-0" def migrate_frigate_config(config_file: str): @@ -55,12 +55,12 @@ def migrate_frigate_config(config_file: str): os.path.join(EXPORT_DIR, file), os.path.join(EXPORT_DIR, new_name) ) - if previous_version < "0.14.1-0": - logger.info(f"Migrating frigate config from {previous_version} to 0.14.1-0...") - new_config = migrate_0141_0(config) + if previous_version < "0.15-0": + logger.info(f"Migrating frigate config from {previous_version} to 0.15-0...") + new_config = migrate_015_0(config) with open(config_file, "w") as f: yaml.dump(new_config, f) - previous_version = "0.14.1-0" + previous_version = "0.15-0" logger.info("Finished frigate config migration...") @@ -152,8 +152,8 @@ def migrate_014(config: dict[str, dict[str, any]]) -> dict[str, dict[str, any]]: return new_config -def migrate_0141_0(config: dict[str, dict[str, any]]) -> dict[str, dict[str, any]]: - """Handle migrating frigate config to 0.14.1-0""" +def migrate_015_0(config: dict[str, dict[str, any]]) -> dict[str, dict[str, any]]: + """Handle migrating frigate config to 0.15-0""" new_config = config.copy() # migrate record.events to record.alerts and record.detections @@ -240,7 +240,7 @@ def migrate_0141_0(config: dict[str, dict[str, any]]) -> dict[str, dict[str, any new_config["cameras"][name] = camera_config - new_config["version"] = "0.14.1-0" + new_config["version"] = "0.15-0" return new_config