mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-11-25 14:57:07 +03:00
Remove event retain (#25061)
CI / AMD64 Build (push) Waiting to run
CI / AMD64 Smoke Test (push) Blocked by required conditions
CI / ARM Build (push) Waiting to run
CI / Jetson Jetpack 6 (push) Waiting to run
CI / AMD64 Extra Build (push) Blocked by required conditions
CI / ARM Extra Build (push) Blocked by required conditions
CI / Synaptics Build (push) Blocked by required conditions
CI / Assemble and push default build (push) Blocked by required conditions
CI / AMD64 Build (push) Waiting to run
CI / AMD64 Smoke Test (push) Blocked by required conditions
CI / ARM Build (push) Waiting to run
CI / Jetson Jetpack 6 (push) Waiting to run
CI / AMD64 Extra Build (push) Blocked by required conditions
CI / ARM Extra Build (push) Blocked by required conditions
CI / Synaptics Build (push) Blocked by required conditions
CI / Assemble and push default build (push) Blocked by required conditions
* remove event retain and retain_indefinitely
Retaining an event only protected its footage during low-disk cleanup, and cleanup undid that a cycle later: it marked every event in the deleted time window as having no clip, including retained events it had kept, so the next pass deleted their footage. The UI hasn't set the flag in many versions and exports are the supported way to keep footage, so this removes the /events/{event_id}/retain endpoints, the favorites filter and the retain_indefinitely column. Storage cleanup is now a single oldest-first pass. Migration 007 now adds the column with raw SQL because add_fields put the field back on the Event model in the process that ran migrations, which broke inserts after 041 dropped it on fresh installs.
* remove leftover retain_indefinitely from event cleanup test
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import datetime
|
||||
import gc
|
||||
import logging
|
||||
import os
|
||||
import tempfile
|
||||
@@ -477,12 +478,7 @@ class TestHttp(unittest.TestCase):
|
||||
|
||||
id = "123456.keep"
|
||||
time_keep = datetime.datetime.now().timestamp()
|
||||
_insert_mock_event(
|
||||
id,
|
||||
time_keep,
|
||||
time_keep + 30,
|
||||
True,
|
||||
)
|
||||
_insert_mock_event(id, time_keep, time_keep + 30)
|
||||
rec_k_id = "1234567.keep"
|
||||
rec_k2_id = "1234568.keep"
|
||||
rec_k3_id = "1234569.keep"
|
||||
@@ -507,7 +503,7 @@ class TestHttp(unittest.TestCase):
|
||||
|
||||
id2 = "7890.delete"
|
||||
time_delete = datetime.datetime.now().timestamp() - 360
|
||||
_insert_mock_event(id2, time_delete, time_delete + 30, False)
|
||||
_insert_mock_event(id2, time_delete, time_delete + 30)
|
||||
rec_d_id = "78901.delete"
|
||||
rec_d2_id = "78902.delete"
|
||||
rec_d3_id = "78903.delete"
|
||||
@@ -540,14 +536,15 @@ class TestHttp(unittest.TestCase):
|
||||
Recordings.get(Recordings.id == rec_d2_id)
|
||||
Recordings.get(Recordings.id == rec_d3_id)
|
||||
|
||||
def test_storage_cleanup_keeps_retained(self):
|
||||
"""Ensure cleanup steps over retained segments to reach newer ones."""
|
||||
def test_storage_cleanup_deletes_oldest_first(self):
|
||||
"""Ensure cleanup deletes the oldest segments and only expires their events."""
|
||||
config = FrigateConfig(**self.minimal_config)
|
||||
storage = StorageMaintainer(config, MagicMock())
|
||||
|
||||
seg_len = 600
|
||||
base = datetime.datetime.now().timestamp() - 7200
|
||||
_insert_mock_event("123456.keep", base, base + 2.5 * seg_len, True)
|
||||
_insert_mock_event("old.event", base, base + 2.5 * seg_len)
|
||||
_insert_mock_event("new.event", base + 8 * seg_len, base + 9.5 * seg_len)
|
||||
|
||||
paths = {}
|
||||
for i in range(10):
|
||||
@@ -557,16 +554,23 @@ class TestHttp(unittest.TestCase):
|
||||
rec_id, paths[rec_id], base + i * seg_len, base + (i + 1) * seg_len
|
||||
)
|
||||
|
||||
# Hourly bandwidth is 48 MB, so cleanup needs all 56 MB of unretained
|
||||
# segments and must pass the older retained ones to get there.
|
||||
# Hourly bandwidth is 48 MB, so cleanup removes the oldest 56 MB
|
||||
storage.calculate_camera_bandwidth()
|
||||
storage.reduce_storage_consumption()
|
||||
|
||||
retained = {"segment-0", "segment-1", "segment-2"}
|
||||
# flush the queued writes, and collect the abandoned recordings
|
||||
# cursor so this connection stops reading its stale snapshot
|
||||
self.db.stop()
|
||||
self.db.start()
|
||||
gc.collect()
|
||||
|
||||
kept = {"segment-7", "segment-8", "segment-9"}
|
||||
remaining = {r.id for r in Recordings.select(Recordings.id)}
|
||||
on_disk = {rec_id for rec_id, path in paths.items() if os.path.exists(path)}
|
||||
self.assertEqual(remaining, retained)
|
||||
self.assertEqual(on_disk, retained)
|
||||
self.assertEqual(remaining, kept)
|
||||
self.assertEqual(on_disk, kept)
|
||||
self.assertFalse(Event.get(Event.id == "old.event").has_clip)
|
||||
self.assertTrue(Event.get(Event.id == "new.event").has_clip)
|
||||
self.assertFalse(storage.retention_unmet)
|
||||
|
||||
def test_unmet_retention_sets_the_live_flag(self):
|
||||
@@ -596,7 +600,6 @@ def _insert_mock_event(
|
||||
id: str,
|
||||
start: int,
|
||||
end: int,
|
||||
retain: bool,
|
||||
camera: str = "front_door",
|
||||
label: str = "Mock",
|
||||
) -> Event:
|
||||
@@ -616,7 +619,6 @@ def _insert_mock_event(
|
||||
area=0,
|
||||
has_clip=True,
|
||||
has_snapshot=True,
|
||||
retain_indefinitely=retain,
|
||||
).execute()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user