Files
opencode-manager/frontend/src/hooks/useVcsInfo.ts
T
Chris Scott b0a1640565 fix(frontend): harden the persisted query cache
Persist only data that survives a JSON round trip, bound both the age and
the size of what is written, and stop a restore from being read as a
missing or empty list.

- Drop the repository git status rule: its `Map` data serializes to `{}`,
  so a restored cache made `gitStatuses.get` throw. Round-trip every
  remaining rule through the real persister to catch class-backed data.
- Persist only the unfiltered session list and give just that list the 24h
  gcTime; a search key keeps the default and is collected when unused.
- Set the 24h gcTime in the vcs info query options instead of a prefix
  default, so vcs status and diff keep their normal gcTime.
- Drop the oldest half of the persisted queries per retry pass instead of
  one per pass, sorting once per save, and cap infinite queries to their
  first page before the write.
- Build the session-pin and active-work rules from the shared keys.
2026-10-24 19:24:26 -04:00

27 lines
812 B
TypeScript

import { useQuery } from '@tanstack/react-query'
import { getVcsInfo } from '@/api/opencode'
import { vcsInfoQueryKey } from '@/lib/queryInvalidation'
import { PERSISTED_CACHE_MAX_AGE_MS } from '@/lib/queryPersistence'
export interface UseVcsInfoOptions {
enabled?: boolean
}
export function useVcsInfo(
directory: string | undefined,
serverId: string | undefined,
options: UseVcsInfoOptions = {},
) {
const { enabled = true } = options
return useQuery({
queryKey: vcsInfoQueryKey(directory, serverId),
queryFn: () => getVcsInfo(directory ?? '', serverId),
enabled: enabled && Boolean(directory),
staleTime: 30_000,
/** The key is only persisted when it ends in `info`, which a prefix default cannot express. */
gcTime: PERSISTED_CACHE_MAX_AGE_MS,
retry: false,
})
}