mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-11-05 05:10:33 +03:00
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().
This commit is contained in:
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user