Speed up startup by persisting some queries (#9594)

* persist startup queries

* Use IDB for query storage (#9687)

* Add storage abstraction for persisted query data

Introduce a platform-specific storage abstraction layer for react-query
persistence:
- Native: Uses MMKV for high-performance synchronous storage
- Web: Uses IndexedDB via the `idb` library for efficient async storage

This replaces the previous AsyncStorage implementation with more performant
platform-native solutions. The abstraction maintains API compatibility with
@tanstack/query-async-storage-persister.

* Refactor storage abstraction to use factory pattern

Change createPersistedQueryStorage to a factory function that accepts a
storage ID, allowing multiple isolated storage instances:
- Native: Each instance gets its own MMKV store
- Web: Each instance gets its own IndexedDB database

Adopt the factory pattern in:
- react-query.tsx: Uses 'persisted_queries' storage
- ageAssurance/data.tsx: Uses 'age_assurance' storage

This provides better separation between different query client caches
and allows each to be managed independently.

---------

Co-authored-by: Claude <noreply@anthropic.com>

* Refactor to use archival storage

(cherry picked from commit a773b40e41c96f821cd32260919ce1437c0fc3ab)

* Improve archive db types

(cherry picked from commit 80e4959ba2aa00c984c26aed2f7dfae1095720b0)

* rm idb

* clear on logout, bust on app version

* create abstraction for persisting queries, make gcTime infinite

* Rm abstraction

---------

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Eric Bailey <git@esb.lol>
This commit is contained in:
Samuel Newman
2026-02-02 19:55:01 +02:00
committed by GitHub
parent bfd5ed480f
commit 4f1d4821c5
16 changed files with 304 additions and 89 deletions
+8 -8
View File
@@ -6,17 +6,17 @@ export function create({id}: {id: string}): DB {
const store = new MMKV({id})
return {
async get(key: string): Promise<string | undefined> {
return store.getString(key) ?? undefined
get(key: string) {
return store.getString(key)
},
async set(key: string, value: string): Promise<void> {
store.set(key, value)
set(key: string, value: string) {
return store.set(key, value)
},
async delete(key: string): Promise<void> {
store.delete(key)
delete(key: string) {
return store.delete(key)
},
async clear(): Promise<void> {
store.clearAll()
clear() {
return store.clearAll()
},
}
}
+8 -8
View File
@@ -6,17 +6,17 @@ export function create({id}: {id: string}): DB {
const store = createStore(id, id)
return {
async get(key: string): Promise<string | undefined> {
return get(key, store) ?? undefined
get(key: string) {
return get(key, store)
},
async set(key: string, value: string): Promise<void> {
await set(key, value, store)
set(key: string, value: string) {
return set(key, value, store)
},
async delete(key: string): Promise<void> {
await del(key, store)
delete(key: string) {
return del(key, store)
},
async clear(): Promise<void> {
await clear(store)
clear() {
return clear(store)
},
}
}
+5 -4
View File
@@ -1,6 +1,7 @@
type MaybePromise<T> = T | Promise<T>
export type DB = {
get(key: string): Promise<string | undefined>
set(key: string, value: string): Promise<void>
delete(key: string): Promise<void>
clear(): Promise<void>
get(key: string): MaybePromise<string | undefined>
set(key: string, value: string): MaybePromise<void>
delete(key: string): MaybePromise<void>
clear(): MaybePromise<void>
}