From bd6aed47eeb0897066567976f37c99f6da47e96b Mon Sep 17 00:00:00 2001 From: Jack Danger Date: Sat, 27 Jun 2026 23:49:20 +0000 Subject: [PATCH] Avoid full-table scan in /recordings/unavailable The query filtered on (end_time >= after AND start_time <= before). With before defaulting to now, start_time <= before matches every row, so SQLite range-scans the entire recordings table for any window. Add a start_time lower bound (segments are short, so a recording overlapping the window starts within an hour of it). Also fix a 500 on cameras=all, where cameras was reassigned to a list and later .split(). --- frigate/api/record.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/frigate/api/record.py b/frigate/api/record.py index 04b81cf38a..23a36a2649 100644 --- a/frigate/api/record.py +++ b/frigate/api/record.py @@ -274,7 +274,7 @@ async def no_recordings( return JSONResponse(content=[]) cameras = ",".join(filtered) else: - cameras = allowed_cameras + cameras = "all" before = params.before or datetime.datetime.now().timestamp() after = ( @@ -283,7 +283,11 @@ async def no_recordings( ) scale = params.scale - clauses = [(Recordings.end_time >= after) & (Recordings.start_time <= before)] + clauses = [ + (Recordings.start_time >= after - 3600) + & (Recordings.start_time <= before) + & (Recordings.end_time >= after) + ] if cameras != "all": camera_list = cameras.split(",") clauses.append((Recordings.camera << camera_list))