From 9f0d29feabc401a99e4f5fdd29fc0c94e222ea29 Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Thu, 12 Dec 2024 06:18:41 -0700 Subject: [PATCH 1/5] Fix single event return --- frigate/events/cleanup.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/frigate/events/cleanup.py b/frigate/events/cleanup.py index b1b485c3d2..da8dbacdfe 100644 --- a/frigate/events/cleanup.py +++ b/frigate/events/cleanup.py @@ -257,7 +257,11 @@ def expire_clips(self) -> list[str]: events_to_update = [] for batch in query.iterator(): - events_to_update.extend([event.id for event in batch]) + try: + events_to_update.extend([event.id for event in batch]) + except TypeError: + events_to_update.append(batch) + if len(events_to_update) >= CHUNK_SIZE: logger.debug( f"Updating {update_params} for {len(events_to_update)} events" From 1a23fdeff2b772078d782b44bca8b85e5ad71625 Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Thu, 12 Dec 2024 06:26:04 -0700 Subject: [PATCH 2/5] Allow customizing if search is preserved for overlay state --- web/src/hooks/use-overlay-state.tsx | 3 ++- web/src/pages/Events.tsx | 33 +++++++++++++++++------------ 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/web/src/hooks/use-overlay-state.tsx b/web/src/hooks/use-overlay-state.tsx index 841585b25d..7a43383d47 100644 --- a/web/src/hooks/use-overlay-state.tsx +++ b/web/src/hooks/use-overlay-state.tsx @@ -5,6 +5,7 @@ import { usePersistence } from "./use-persistence"; export function useOverlayState( key: string, defaultValue: S | undefined = undefined, + preserveSearch: boolean = true, ): [S | undefined, (value: S, replace?: boolean) => void] { const location = useLocation(); const navigate = useNavigate(); @@ -15,7 +16,7 @@ export function useOverlayState( (value: S, replace: boolean = false) => { const newLocationState = { ...currentLocationState }; newLocationState[key] = value; - navigate(location.pathname + location.search, { + navigate(location.pathname + (preserveSearch ? location.search : ""), { state: newLocationState, replace, }); diff --git a/web/src/pages/Events.tsx b/web/src/pages/Events.tsx index 8c6f3cd381..d13cd6e10b 100644 --- a/web/src/pages/Events.tsx +++ b/web/src/pages/Events.tsx @@ -39,8 +39,11 @@ export default function Events() { const [showReviewed, setShowReviewed] = usePersistence("showReviewed", false); - const [recording, setRecording] = - useOverlayState("recording"); + const [recording, setRecording] = useOverlayState( + "recording", + undefined, + false, + ); useSearchEffect("id", (reviewId: string) => { axios @@ -50,18 +53,20 @@ export default function Events() { const startTime = resp.data.start_time - REVIEW_PADDING; const date = new Date(startTime * 1000); - setReviewFilter({ - after: getBeginningOfDayTimestamp(date), - before: getEndOfDayTimestamp(date), - }); - setRecording( - { - camera: resp.data.camera, - startTime, - severity: resp.data.severity, - }, - true, - ); + setTimeout(() => { + setReviewFilter({ + after: getBeginningOfDayTimestamp(date), + before: getEndOfDayTimestamp(date), + }); + setRecording( + { + camera: resp.data.camera, + startTime, + severity: resp.data.severity, + }, + true, + ); + }, 100); } }) .catch(() => {}); From 2715fcaf23dc25b22b82a7a4b2db0346f2e9a42b Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Thu, 12 Dec 2024 06:26:59 -0700 Subject: [PATCH 3/5] Remove timeout --- web/src/pages/Events.tsx | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/web/src/pages/Events.tsx b/web/src/pages/Events.tsx index d13cd6e10b..28625bbd83 100644 --- a/web/src/pages/Events.tsx +++ b/web/src/pages/Events.tsx @@ -53,20 +53,18 @@ export default function Events() { const startTime = resp.data.start_time - REVIEW_PADDING; const date = new Date(startTime * 1000); - setTimeout(() => { - setReviewFilter({ - after: getBeginningOfDayTimestamp(date), - before: getEndOfDayTimestamp(date), - }); - setRecording( - { - camera: resp.data.camera, - startTime, - severity: resp.data.severity, - }, - true, - ); - }, 100); + setReviewFilter({ + after: getBeginningOfDayTimestamp(date), + before: getEndOfDayTimestamp(date), + }); + setRecording( + { + camera: resp.data.camera, + startTime, + severity: resp.data.severity, + }, + true, + ); } }) .catch(() => {}); From 2b8ec3ebac7b0bda56f69a665f0d29b37b208dab Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Thu, 12 Dec 2024 07:11:29 -0700 Subject: [PATCH 4/5] Cleanup --- frigate/events/cleanup.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/frigate/events/cleanup.py b/frigate/events/cleanup.py index da8dbacdfe..675d4e76f1 100644 --- a/frigate/events/cleanup.py +++ b/frigate/events/cleanup.py @@ -257,10 +257,7 @@ def expire_clips(self) -> list[str]: events_to_update = [] for batch in query.iterator(): - try: - events_to_update.extend([event.id for event in batch]) - except TypeError: - events_to_update.append(batch) + events_to_update.append(batch) if len(events_to_update) >= CHUNK_SIZE: logger.debug( From 1c3d1c25fdd948bc522a0d78f935981a7ace1091 Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Thu, 12 Dec 2024 07:12:03 -0700 Subject: [PATCH 5/5] Cleanup naming --- frigate/events/cleanup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frigate/events/cleanup.py b/frigate/events/cleanup.py index 675d4e76f1..741f0884cd 100644 --- a/frigate/events/cleanup.py +++ b/frigate/events/cleanup.py @@ -256,8 +256,8 @@ def expire_clips(self) -> list[str]: events_to_update = [] - for batch in query.iterator(): - events_to_update.append(batch) + for event in query.iterator(): + events_to_update.append(event) if len(events_to_update) >= CHUNK_SIZE: logger.debug(