Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -151,18 +151,29 @@ export function RunsPage({
},
realtime,
},
{ fallbackData: serverActive.runs, keepPreviousData: true },
{
fallbackData: serverActive.runs,
keepPreviousData: false, // Prevent memory accumulation
dedupingInterval: 5000, // Reduce duplicate requests
},
)
// Note: prefetch next results
const { data: nextActiveRuns } = useActiveRuns({
project,
search: {
...debouncedActiveSearch,
page: (debouncedActiveSearch.page ?? 1) + 1,
sourceGroup: debouncedSourceGroup,
// Note: prefetch next results only on first page to reduce memory usage
const shouldPrefetch = (debouncedActiveSearch.page ?? 1) === 1
const { data: nextActiveRuns } = useActiveRuns(
{
project,
search: {
...debouncedActiveSearch,
page: (debouncedActiveSearch.page ?? 1) + 1,
sourceGroup: debouncedSourceGroup,
},
realtime: false,
},
realtime: false,
})
{
isPaused: () => !shouldPrefetch, // Only prefetch on first page
dedupingInterval: 5000,
},
)

const { data: activeCountBySource, isLoading: isActiveCountLoading } = use(
ActiveRunsCountContext,
Expand All @@ -189,7 +200,10 @@ export function RunsPage({
initialItems: serverCompleted.runs,
sourceGroup: debouncedSourceGroup,
},
{ keepPreviousData: true },
{
keepPreviousData: false, // Prevent memory accumulation
dedupingInterval: 5000, // Reduce duplicate requests
},
)

// Update completed runs store on run ended
Expand Down
25 changes: 24 additions & 1 deletion apps/web/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,30 @@ export default function RootLayout({
>
<NextTopLoader showSpinner={false} />
<DatadogProvider>
<SWRProvider config={{ revalidateOnFocus: false }}>
<SWRProvider
config={{
revalidateOnFocus: false,
dedupingInterval: 5000, // Prevent duplicate requests within 5s
provider: () => {
// Limit cache size to prevent memory issues
const map = new Map()
const maxSize = 100 // Keep only 100 most recent cache entries
return {
get: (key: string) => map.get(key),
set: (key: string, value: any) => {
if (map.size >= maxSize) {
// Remove oldest entry when cache is full
const firstKey = map.keys().next().value
map.delete(firstKey)
}
map.set(key, value)
},
delete: (key: string) => map.delete(key),
keys: () => Array.from(map.keys()),
} as any
},
}}
>
<ThemeProvider
attribute='class'
defaultTheme='light'
Expand Down
4 changes: 3 additions & 1 deletion apps/web/src/stores/completedRunsKeysetPagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ export function useCompletedRunsKeysetPaginationStore(
fetcher,
{
...opts,
keepPreviousData: true,
keepPreviousData: false, // Prevent memory accumulation
dedupingInterval: opts?.dedupingInterval ?? 5000, // Prevent duplicate requests within 5s
revalidateOnFocus: false, // Prevent refetch on tab focus
fallbackData:
initialItems.length > 0
? {
Expand Down
6 changes: 5 additions & 1 deletion apps/web/src/stores/evaluationResultsV2/bySpans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ export default function useEvaluationResultsV2BySpans(
])
: undefined,
fetcher,
opts,
{
...opts,
dedupingInterval: opts?.dedupingInterval ?? 5000, // Prevent duplicate requests within 5s
revalidateOnFocus: false, // Prevent refetch on tab focus
},
)

return {
Expand Down
6 changes: 5 additions & 1 deletion apps/web/src/stores/evaluationsV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ export function useEvaluationsV2(
document.documentUuid,
]),
fetcher,
opts,
{
...opts,
dedupingInterval: opts?.dedupingInterval ?? 5000, // Prevent duplicate requests within 5s
revalidateOnFocus: false, // Prevent refetch on tab focus
},
)

const {
Expand Down
12 changes: 10 additions & 2 deletions apps/web/src/stores/runs/activeRuns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ export function useActiveRuns(
search?.pageSize,
],
fetcher,
opts,
{
...opts,
dedupingInterval: opts?.dedupingInterval ?? 5000, // Prevent duplicate requests within 5s
revalidateOnFocus: false, // Prevent refetch on tab focus
},
)

const { createStreamHandler, hasActiveStream, createAbortController } =
Expand Down Expand Up @@ -157,7 +161,11 @@ export function useActiveRunsCount(
} = useSWR<Record<LogSources, number>>(
['activeRunsCount', project.id],
fetcher,
opts,
{
...opts,
dedupingInterval: opts?.dedupingInterval ?? 5000, // Prevent duplicate requests within 5s
revalidateOnFocus: false, // Prevent refetch on tab focus
},
)

const onMessage = useCallback(
Expand Down
12 changes: 10 additions & 2 deletions apps/web/src/stores/runs/completedRuns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ export function useCompletedRuns(
} = useSWR<{ items: CompletedRun[]; next: string | null }>(
['completedRuns', project.id, search?.sourceGroup, search?.limit],
fetcher,
opts,
{
...opts,
dedupingInterval: opts?.dedupingInterval ?? 5000, // Prevent duplicate requests within 5s
revalidateOnFocus: false, // Prevent refetch on tab focus
},
)

const onMessage = useCallback(
Expand Down Expand Up @@ -109,7 +113,11 @@ export function useCompletedRunsCount(
} = useSWR<Record<LogSources, number>>(
['completedRunsCount', project.id],
fetcher,
opts,
{
...opts,
dedupingInterval: opts?.dedupingInterval ?? 5000, // Prevent duplicate requests within 5s
revalidateOnFocus: false, // Prevent refetch on tab focus
},
)

const onMessage = useCallback(
Expand Down
6 changes: 5 additions & 1 deletion apps/web/src/stores/traces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ export function useTrace(
data = undefined,
isLoading,
mutate,
} = useSWR<AssembledTrace>(traceId, fetcher, opts)
} = useSWR<AssembledTrace>(traceId, fetcher, {
...opts,
dedupingInterval: opts?.dedupingInterval ?? 5000, // Prevent duplicate requests within 5s
revalidateOnFocus: false, // Prevent refetch on tab focus
})

return useMemo(() => ({ data, isLoading, mutate }), [data, isLoading, mutate])
}
Loading
Loading