Paginated live query fetches entire collection if shared rows unload while the first page is in flight
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 48/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- typescript
- Ambito
- database
Direzione di ricerca
Start with packages/db/src/query/live/ordered-source-loader.ts, especially invalidateSourceOrdering, and read the ownership cleanup path in cleanupQueryInternal alongside the linked issues #1880, #1886 and #2194. Run the supplied reproduction as packages/query-db-collection/tests/ownership-cleanup-repro.test.ts with npx vitest run tests/ownership-cleanup-repro.test.ts from packages/query-db-collection, then inspect the four named failures in the ordered source loader oracle tests. Done means the reproduction passes while those existing tests continue to pass and the first-page request remains bounded.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Title: Paginated live query fetches entire collection if shared rows unload while its first page is in flight
- I've validated the bug against the latest version of DB packages
Describe the bug
Follow-up to #1880, #1886 and #2194.
One syncMode: 'on-demand' query collection serves two live queries:
- Query A loads rows by id:
where(inArray(id, ids)). - Query B is paginated:
orderBy(createdAt desc).orderBy(id desc)withuseLiveInfiniteQuery.
Here's what happens when the app navigates from a page that uses query A to a page that uses query B:
- Query B mounts and requests its first page.
- Query A unmounts before that page returns, and its rows unload.
- B then requests the whole collection: no
where,orderByorlimit.
Expected: one page. Actual: the whole collection is requested until query B is usable. (In my situation, it's 100,000 rows!)
I can reliably reproduce this behavior by flipping on 3G throttling.
Cause:
- B begins by showing rows already in the collection from A. B also requests its first page.
- A unloads.
cleanupQueryInternaldeletes the rows that no other subset owns. OrderedSourceLoader.onSourceChangessees deletes of rows that B shows. It callsinvalidateSourceOrdering().- No request has settled, so the loader owes
fullrepair, notbounded. - The loader calls
loadFullSource().
If B's first page arrives before A unloads its rows, then everything behaves as expected: B re-fetches just one page.
To Reproduce
ownership-cleanup-repro.test.ts
Put the attached file named ownership-cleanup-repro.test.ts in packages/query-db-collection/tests/. Then, in packages/query-db-collection run:
npx vitest run tests/ownership-cleanup-repro.test.ts
Result:
AssertionError: expected [ { offset: undefined } ] to deeply equal []
The first test unloads query A while query B's first page is held. The second test is the control: it deletes after the first page settles.
Reproduces on @tanstack/db 0.15.2, @tanstack/query-db-collection 1.4.8 and main (d2935d0).
Expected behavior
B re-fetches one page, whether A unloads before or after B's first page arrives.
Screenshots
N/A
Desktop (please complete the following information):
- OS: macOS. The test also reproduces it in Node.
- Browser: any
- Version: N/A
Smartphone (please complete the following information):
N/A
Additional context
A possible change in invalidateSourceOrdering:
// packages/db/src/query/live/ordered-source-loader.ts
this.oweDebt(
- this.hasSettledSourceRequest && this.work.kind === `idle`
+ !this.hasSettledSourceRequest || this.work.kind === `idle`
? `bounded`
: `full`,
)
The change makes the repro pass. But it breaks tests, so I have not opened a PR.
- #1886: the one-page repair runs only when the first page has arrived and no request is in flight.
- #2194: it also runs with requests in flight, but still only after the first page arrives.
- Before the first page arrives, the loader still reads the whole collection.
With the change, 14 cases fail in four tests in ordered-source-loader-state-oracle.test.ts and ordered-source-loader-oracle.test.ts:
- "keeps full-source recovery authoritative across an initial page overlap"
- "a page failure while a full-source demand is held releases only the page"
- "repairs ordering before an explicit window consumes a staged ordinary continuation"
- "releases each failed lease once, at a covering replay or the explicit retry"
My fix breaks these tests. I'm sure I don't understand the deeper reasoning. Is there a reason the loader needs to fetch the whole collection here? Please let me know if it is appropriate to open a PR for this.
- Lingua principale
- TypeScript
- Stelle
- 4k
- Fork
- 277
- Merge medio
- 21h 21m
- PR unite (30g)
- 218
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di TanStack/db
-
Difficoltà 1/5 1-3 ore Idoneità per principianti 88/100
I maintainer di solito rispondono entro 1 giorno
-
OfflineExecutor.dispose() never settles pendingTransactionPromisesForse già presa @Claire-ovo l’ha presa 1 giorno fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
TanStack/db#2254 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 1-2 giorni Idoneità per principianti 58/100
I maintainer di solito rispondono entro 1 giorno
Issue simili
-
New icon: `filter-clear`Apertacalcite-ui-icons enhancement impact - p3 - not time sensitive needs triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 67/100
Esri/calcite-design-system#15467 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
diegosouzapw/OmniRoute#18390 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
-
Difficoltà 1/5 1-3 ore Idoneità per principianti 86/100
guilhermerodz/input-otp#157 · 1 commento ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
davidjerleke/embla-carousel#1414 ·
I maintainer di solito rispondono entro 4 giorni