fix(search): cache paging data before combining, not after - #414
Merged
Conversation
Typing in the search bar killed the process on the first keystroke: java.lang.IllegalStateException: Attempt to collect twice from pageEventFlow, which is an illegal operation. A PagingData taken straight from a Pager may only be collected once. combine re-emits the latest value of every source whenever any single one of them changes, and extensionSearchResults always emits twice per query — an empty placeholder, then the results — so the same PagingData reached the collector a second time. cachedIn was already there but sat after the combine, where it received the duplicate rather than preventing it. Moving it onto localSearchResults makes the stream multicast; filter and insertHeaderItem still run on every collection, which is what they are meant to do. Searching looked like it simply returned nothing, which is why the SQL was suspected first — it was never at fault. Two tests come with it, including one that reproduces the exception when the cache is absent, so a green suite cannot go quiet on this again. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
oxyroid
approved these changes
Aug 9, 2026
Owner
|
thanks for your contribution |
oxyroid
pushed a commit
that referenced
this pull request
Aug 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Typing into the search bar kills the process on the first keystroke:
Cause
A
PagingDatataken straight from aPagermay only be collected once.AppViewModel.channelscombines three sources, andcombinere-emits thelatest value of every source whenever any single one of them changes.
extensionSearchResultsalways emits twice per query — an empty placeholderfirst, then the results — so the same
PagingDatareaches the collector asecond time and Paging throws.
cachedInwas already there, but placed after thecombine, where itreceives the duplicate rather than preventing it. Moving it onto
localSearchResultsmakes the stream multicast;filterandinsertHeaderItemstill run on every collection, which is what they are meantto do.
Why it looked like something else
Search appeared to return nothing, so the SQL was the natural suspect — it is
not at fault. The process simply died before any result could be rendered.
Tests
Two, and the second is the point: it builds the same shape without the cache
and asserts that Paging rejects the second collection. A regression here would
otherwise pass a green suite quietly, since the symptom is an empty list rather
than a failure.
Verified on device (Android 9, arm64): before, the process died on the first
keystroke; after, a search returns its results and survives several queries in
a row.