From f8f8f44bfbfd27d66cfe6d6f5725c5c052f2f44e Mon Sep 17 00:00:00 2001 From: Wes Date: Thu, 31 Oct 2024 11:45:02 +1100 Subject: [PATCH] fix: clear events when streaming starts (#3266) See #3260 We can get some console connection errors in our deployed environment which causes streaming to get restarted. However, it seems like we don't clear the cache when this happens so duplicate events get returned from our streaming hooks. This change should ensure the events are cleared anytime we restart the stream. --- frontend/console/src/api/timeline/use-timeline.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/frontend/console/src/api/timeline/use-timeline.ts b/frontend/console/src/api/timeline/use-timeline.ts index 04c5853374..39e839f671 100644 --- a/frontend/console/src/api/timeline/use-timeline.ts +++ b/frontend/console/src/api/timeline/use-timeline.ts @@ -37,6 +37,10 @@ export const useTimeline = (isStreaming: boolean, filters: EventsQuery_Filter[], try { console.debug('streaming timeline') console.debug('timeline-filters:', filters) + + // Clear the cache when starting a new stream + queryClient.setQueryData(queryKey, (_ = []) => []) + for await (const response of client.streamEvents( { updateInterval: { seconds: BigInt(0), nanos: updateIntervalMs * 1000 }, query: { limit, filters, order } }, { signal },