From c0a47340543f41208881a4be3b0da2a216b3e8c7 Mon Sep 17 00:00:00 2001 From: nick-delirium Date: Mon, 31 Mar 2025 17:14:23 +0200 Subject: [PATCH] ui: fix double fetches for sessions --- frontend/app/PrivateRoutes.tsx | 4 ++-- .../shared/LiveSessionSearch/LiveSessionSearch.tsx | 6 ++++-- .../components/shared/SessionFilters/SessionFilters.tsx | 3 --- frontend/app/hooks/useSessionSearchQueryHandler.ts | 7 +------ frontend/app/layout/SideMenu.tsx | 2 +- 5 files changed, 8 insertions(+), 14 deletions(-) diff --git a/frontend/app/PrivateRoutes.tsx b/frontend/app/PrivateRoutes.tsx index aacb1b133..9169d9344 100644 --- a/frontend/app/PrivateRoutes.tsx +++ b/frontend/app/PrivateRoutes.tsx @@ -125,13 +125,13 @@ function PrivateRoutes() { }, [siteId]); React.useEffect(() => { - debounceSearch = debounce(() => searchStore.fetchSessions(), 500); + debounceSearch = debounce(() => searchStore.fetchSessions(), 250); }, []); React.useEffect(() => { if (!searchStore.urlParsed) return; debounceSearch(); - }, [searchStore.instance.filters, searchStore.instance.eventsOrder]); + }, [searchStore.urlParsed, searchStore.instance.filters, searchStore.instance.eventsOrder]); return ( }> diff --git a/frontend/app/components/shared/LiveSessionSearch/LiveSessionSearch.tsx b/frontend/app/components/shared/LiveSessionSearch/LiveSessionSearch.tsx index c6faa550b..a2b694b61 100644 --- a/frontend/app/components/shared/LiveSessionSearch/LiveSessionSearch.tsx +++ b/frontend/app/components/shared/LiveSessionSearch/LiveSessionSearch.tsx @@ -9,8 +9,10 @@ function LiveSessionSearch() { const appliedFilter = searchStoreLive.instance; useEffect(() => { - void searchStoreLive.fetchSessions(); - }, []); + if (projectsStore.activeSiteId) { + void searchStoreLive.fetchSessions(true); + } + }, [projectsStore.activeSiteId]) const onAddFilter = (filter: any) => { filter.autoOpen = true; diff --git a/frontend/app/components/shared/SessionFilters/SessionFilters.tsx b/frontend/app/components/shared/SessionFilters/SessionFilters.tsx index 3046404cd..a4f060426 100644 --- a/frontend/app/components/shared/SessionFilters/SessionFilters.tsx +++ b/frontend/app/components/shared/SessionFilters/SessionFilters.tsx @@ -53,9 +53,6 @@ function SessionFilters() { onBeforeLoad: async () => { await reloadTags(); }, - onLoaded: () => { - debounceFetch = debounce(() => searchStore.fetchSessions(), 500); - } }); const onAddFilter = (filter: any) => { diff --git a/frontend/app/hooks/useSessionSearchQueryHandler.ts b/frontend/app/hooks/useSessionSearchQueryHandler.ts index c6a1c6dfd..02dd88b72 100644 --- a/frontend/app/hooks/useSessionSearchQueryHandler.ts +++ b/frontend/app/hooks/useSessionSearchQueryHandler.ts @@ -49,13 +49,8 @@ const useSessionSearchQueryHandler = ({ searchStore.applyFilter(filter, true); } - // Important: Mark URL as parsed BEFORE fetching - // This prevents the initial fetch when the URL is parsed searchStore.setUrlParsed(); - - // Then fetch sessions - this is the only place that should fetch initially - await searchStore.fetchSessions(); - onLoaded(); + onLoaded?.(); } catch (error) { console.error('Error applying filter from query:', error); searchStore.setUrlParsed(); diff --git a/frontend/app/layout/SideMenu.tsx b/frontend/app/layout/SideMenu.tsx index 28df5adfe..c57b8561f 100644 --- a/frontend/app/layout/SideMenu.tsx +++ b/frontend/app/layout/SideMenu.tsx @@ -255,7 +255,7 @@ function SideMenu(props: Props) { {t('Beta')}