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.")
|
||||
|
||||
|
||||
class ReviewRetainConfig(FrigateBaseModel):
|
||||
days: float = Field(default=10, title="Default retention period.")
|
||||
mode: RetainModeEnum = Field(default=RetainModeEnum.motion, title="Retain mode.")
|
||||
|
||||
|
||||
class EventsConfig(FrigateBaseModel):
|
||||
pre_capture: int = Field(
|
||||
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.")
|
||||
retain: RecordRetainConfig = Field(
|
||||
default_factory=RecordRetainConfig, title="Event retention settings."
|
||||
retain: ReviewRetainConfig = Field(
|
||||
default_factory=ReviewRetainConfig, title="Event retention settings."
|
||||
)
|
||||
|
||||
|
||||
|
@ -57,11 +57,7 @@ class ExternalEventProcessor:
|
||||
thumbnail = self._write_images(
|
||||
camera_config, label, event_id, draw, snapshot_frame
|
||||
)
|
||||
end = (
|
||||
now + duration + camera_config.record.events.post_capture
|
||||
if duration is not None
|
||||
else None
|
||||
)
|
||||
end = now + duration if duration is not None else None
|
||||
|
||||
self.event_sender.publish(
|
||||
(
|
||||
@ -74,7 +70,7 @@ class ExternalEventProcessor:
|
||||
"sub_label": sub_label,
|
||||
"score": score,
|
||||
"camera": camera,
|
||||
"start_time": now - camera_config.record.events.pre_capture,
|
||||
"start_time": now,
|
||||
"end_time": end,
|
||||
"thumbnail": thumbnail,
|
||||
"has_clip": camera_config.record.enabled and include_recording,
|
||||
|
@ -5,9 +5,11 @@ import itertools
|
||||
import logging
|
||||
import os
|
||||
import threading
|
||||
from functools import reduce
|
||||
from multiprocessing.synchronize import Event as MpEvent
|
||||
from pathlib import Path
|
||||
|
||||
from peewee import operator
|
||||
from playhouse.sqlite_ext import SqliteExtDatabase
|
||||
|
||||
from frigate.config import CameraConfig, FrigateConfig, RetainModeEnum
|
||||
@ -71,17 +73,26 @@ class RecordingCleanup(threading.Thread):
|
||||
).timestamp()
|
||||
expired_reviews: ReviewSegment = (
|
||||
ReviewSegment.select(ReviewSegment.id)
|
||||
.where(ReviewSegment.camera == "front_cam")
|
||||
.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
|
||||
)
|
||||
reduce(
|
||||
operator.or_,
|
||||
[
|
||||
reduce(
|
||||
operator.and_,
|
||||
[
|
||||
(ReviewSegment.severity == "alert"),
|
||||
(ReviewSegment.end_time < alert_expire_date),
|
||||
],
|
||||
),
|
||||
reduce(
|
||||
operator.and_,
|
||||
[
|
||||
(ReviewSegment.severity == "detection"),
|
||||
(ReviewSegment.end_time < detection_expire_date),
|
||||
],
|
||||
),
|
||||
],
|
||||
)
|
||||
)
|
||||
.namedtuples()
|
||||
@ -89,7 +100,6 @@ class RecordingCleanup(threading.Thread):
|
||||
|
||||
max_deletes = 100000
|
||||
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]
|
||||
|
Loading…
Reference in New Issue
Block a user