mirror of
https://github.com/browseros-ai/BrowserOS.git
synced 2026-05-13 15:46:22 +00:00
* fix: add refresh indicator to chat history when fetching latest conversations Show a non-blocking "Fetching latest conversations" indicator at the top of the history list while the cached data is being refreshed. Users can still interact with the cached conversation list during the refresh. * perf: reduce chat history query payload — fetch last 2 messages instead of 5 The conversation list only displays the last user message as a preview. Fetching 5 messages per conversation was wasteful — each message contains the full UIMessage object (tool calls, reasoning, etc.) multiplied by 50 conversations per page. Reduced to last 2 which is sufficient to find the last user message in a user→assistant exchange. * perf: use first+DESC instead of last+ASC to push LIMIT down to SQL PostGraphile's `last: N` doesn't map to SQL LIMIT — it uses a padded LIMIT 10 and slices in application code. Changing to `first: 2` with ORDER_INDEX_DESC generates a true SQL LIMIT 2, reducing rows scanned from 500 to 100 per page (50 conversations × 2 vs 10 messages each). No UX impact — extractLastUserMessage() filters by role regardless of message order. * chore: update react query packages * feat: replace localforage with idb-keyval
38 lines
1.0 KiB
TypeScript
38 lines
1.0 KiB
TypeScript
import { createAsyncStoragePersister } from '@tanstack/query-async-storage-persister'
|
|
import { QueryClient } from '@tanstack/react-query'
|
|
import {
|
|
type AsyncStorage,
|
|
PersistQueryClientProvider,
|
|
} from '@tanstack/react-query-persist-client'
|
|
import { del, get, set } from 'idb-keyval'
|
|
import type { FC, ReactNode } from 'react'
|
|
|
|
const queryClient = new QueryClient({
|
|
defaultOptions: {
|
|
queries: {
|
|
gcTime: 1000 * 60 * 60 * 24, // 24 hours
|
|
},
|
|
},
|
|
})
|
|
|
|
const idbStorage: AsyncStorage<string> = {
|
|
getItem: (key: string) => get<string>(key).then((v) => v ?? null),
|
|
setItem: (key: string, value: string) => set(key, value),
|
|
removeItem: (key: string) => del(key),
|
|
}
|
|
|
|
const asyncStoragePersister = createAsyncStoragePersister({
|
|
storage: idbStorage,
|
|
})
|
|
|
|
export const QueryProvider: FC<{ children: ReactNode }> = ({ children }) => {
|
|
return (
|
|
<PersistQueryClientProvider
|
|
persistOptions={{ persister: asyncStoragePersister }}
|
|
client={queryClient}
|
|
>
|
|
{children}
|
|
</PersistQueryClientProvider>
|
|
)
|
|
}
|