mirror of
https://github.com/blakeblackshear/frigate.git
synced 2024-11-21 19:07:46 +01:00
Cleanup after recordings refactor (#13518)
* Cleanup after recordings refactor * Fix default retention mode * Formatting * Fix review item query * Default review retention
This commit is contained in:
parent
21a50cc452
commit
e66f47bdf6
@ -301,13 +301,18 @@ class RecordRetainConfig(FrigateBaseModel):
|
|||||||
mode: RetainModeEnum = Field(default=RetainModeEnum.all, title="Retain mode.")
|
mode: RetainModeEnum = Field(default=RetainModeEnum.all, title="Retain mode.")
|
||||||
|
|
||||||
|
|
||||||
|
class ReviewRetainConfig(FrigateBaseModel):
|
||||||
|
days: float = Field(default=10, title="Default retention period.")
|
||||||
|
mode: RetainModeEnum = Field(default=RetainModeEnum.motion, title="Retain mode.")
|
||||||
|
|
||||||
|
|
||||||
class EventsConfig(FrigateBaseModel):
|
class EventsConfig(FrigateBaseModel):
|
||||||
pre_capture: int = Field(
|
pre_capture: int = Field(
|
||||||
default=5, title="Seconds to retain before event starts.", le=MAX_PRE_CAPTURE
|
default=5, title="Seconds to retain before event starts.", le=MAX_PRE_CAPTURE
|
||||||
)
|
)
|
||||||
post_capture: int = Field(default=5, title="Seconds to retain after event ends.")
|
post_capture: int = Field(default=5, title="Seconds to retain after event ends.")
|
||||||
retain: RecordRetainConfig = Field(
|
retain: ReviewRetainConfig = Field(
|
||||||
default_factory=RecordRetainConfig, title="Event retention settings."
|
default_factory=ReviewRetainConfig, title="Event retention settings."
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -57,11 +57,7 @@ class ExternalEventProcessor:
|
|||||||
thumbnail = self._write_images(
|
thumbnail = self._write_images(
|
||||||
camera_config, label, event_id, draw, snapshot_frame
|
camera_config, label, event_id, draw, snapshot_frame
|
||||||
)
|
)
|
||||||
end = (
|
end = now + duration if duration is not None else None
|
||||||
now + duration + camera_config.record.events.post_capture
|
|
||||||
if duration is not None
|
|
||||||
else None
|
|
||||||
)
|
|
||||||
|
|
||||||
self.event_sender.publish(
|
self.event_sender.publish(
|
||||||
(
|
(
|
||||||
@ -74,7 +70,7 @@ class ExternalEventProcessor:
|
|||||||
"sub_label": sub_label,
|
"sub_label": sub_label,
|
||||||
"score": score,
|
"score": score,
|
||||||
"camera": camera,
|
"camera": camera,
|
||||||
"start_time": now - camera_config.record.events.pre_capture,
|
"start_time": now,
|
||||||
"end_time": end,
|
"end_time": end,
|
||||||
"thumbnail": thumbnail,
|
"thumbnail": thumbnail,
|
||||||
"has_clip": camera_config.record.enabled and include_recording,
|
"has_clip": camera_config.record.enabled and include_recording,
|
||||||
|
@ -5,9 +5,11 @@ import itertools
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import threading
|
import threading
|
||||||
|
from functools import reduce
|
||||||
from multiprocessing.synchronize import Event as MpEvent
|
from multiprocessing.synchronize import Event as MpEvent
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
from peewee import operator
|
||||||
from playhouse.sqlite_ext import SqliteExtDatabase
|
from playhouse.sqlite_ext import SqliteExtDatabase
|
||||||
|
|
||||||
from frigate.config import CameraConfig, FrigateConfig, RetainModeEnum
|
from frigate.config import CameraConfig, FrigateConfig, RetainModeEnum
|
||||||
@ -71,17 +73,26 @@ class RecordingCleanup(threading.Thread):
|
|||||||
).timestamp()
|
).timestamp()
|
||||||
expired_reviews: ReviewSegment = (
|
expired_reviews: ReviewSegment = (
|
||||||
ReviewSegment.select(ReviewSegment.id)
|
ReviewSegment.select(ReviewSegment.id)
|
||||||
|
.where(ReviewSegment.camera == "front_cam")
|
||||||
.where(
|
.where(
|
||||||
ReviewSegment.camera == config.name
|
reduce(
|
||||||
and (
|
operator.or_,
|
||||||
(
|
[
|
||||||
ReviewSegment.severity == "alert"
|
reduce(
|
||||||
and ReviewSegment.end_time < alert_expire_date
|
operator.and_,
|
||||||
)
|
[
|
||||||
or (
|
(ReviewSegment.severity == "alert"),
|
||||||
ReviewSegment.severity == "detection"
|
(ReviewSegment.end_time < alert_expire_date),
|
||||||
and ReviewSegment.end_time < detection_expire_date
|
],
|
||||||
)
|
),
|
||||||
|
reduce(
|
||||||
|
operator.and_,
|
||||||
|
[
|
||||||
|
(ReviewSegment.severity == "detection"),
|
||||||
|
(ReviewSegment.end_time < detection_expire_date),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.namedtuples()
|
.namedtuples()
|
||||||
@ -89,7 +100,6 @@ class RecordingCleanup(threading.Thread):
|
|||||||
|
|
||||||
max_deletes = 100000
|
max_deletes = 100000
|
||||||
deleted_reviews_list = list(map(lambda x: x[0], 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):
|
for i in range(0, len(deleted_reviews_list), max_deletes):
|
||||||
ReviewSegment.delete().where(
|
ReviewSegment.delete().where(
|
||||||
ReviewSegment.id << deleted_reviews_list[i : i + max_deletes]
|
ReviewSegment.id << deleted_reviews_list[i : i + max_deletes]
|
||||||
|
Loading…
Reference in New Issue
Block a user