agrosner
09/12/2022, 6:34 PMlimit
offset
using query strategy CacheAndNetwork
2. user scrolls / fetch next page called, we query apollo (no watch) for the next set of data.
3. On reentry, Correct: we receive emission for the fully cached dataset (9 items). strange*:* then we receive a final emission for the original query (say its 5 items).
in this situation, would it then be best to just observe cache only and do fetches at will instead (i.e. parallel initial fetch as a query like we do the next page query)bod
09/13/2022, 7:10 AMbod
09/13/2022, 2:29 PMCacheAndNetwork
may be expected, depending on how when/how it's called. I made a little test here and you can see that you'd get first the value in the cache (without the next page), and then the value from the network (so, only the next page).agrosner
09/13/2022, 6:24 PMlimit
/ offset
with a cursor-type pagination return where nextCardIndex
acts like a cursor, we use that for the next offset
in subsequent pages.
2. We wrote a field merger and metadata generator to handle the caching mechanisms for our data (as its not relay-style)
3. It mostly works as expected, except this one case.
4. We watch
the initial query (CacheAndNetwork).
5. We fetch subsequent pages using query()
with NoCache
agrosner
09/13/2022, 6:24 PMwatch
acts as the source of truth for the full set of databod
09/13/2022, 6:32 PMagrosner
09/13/2022, 6:36 PMCacheOnly
on the watch
, and NoCache
on query fetches for each page. The issue is - with the CacheAndNetwork
is that the last emission will be smaller size than what cache has, so we will always use network to page next content even if we have it in the cache.
My assumption was that a watch can ignore parameters with the pagination fieldPolicy. so shouldnt the subsequent cache and network (network return) include both network and cache data merged?bod
09/14/2022, 7:40 AMwatch
with CacheOnly
on one side and query pages with NetworkOnly
on the other side is the way to go.
About CacheAndNetwork
returning the cached (merged) value on the second emission, it could be done but I think there are valid cases where you could actually want only the last page?agrosner
09/14/2022, 2:01 PMagrosner
09/14/2022, 2:03 PMagrosner
09/14/2022, 2:03 PMagrosner
09/14/2022, 2:03 PMagrosner
09/14/2022, 2:05 PMQuery
is generated for pagination that allows no parameters specifically to designate it as the cache observeragrosner
09/14/2022, 2:05 PMbod
09/14/2022, 2:28 PMCacheAndNetwork
or NetworkOnly
) and watch
it. Your UI observes this.
• another coroutine is launched every time you reach the end of the list, which queries the next page with NetworkOnly
. You can ignore the returned data of this one: it's stored in the cache
Both can be the same query, only the parameters change.
Then the first one will be notified with the first page at first, and then with the whole data set (pages merged) when querying next pages.
Does that make sense? Maybe I’m missing something 🙂agrosner
09/14/2022, 2:35 PMCacheAndNetwork
is the one going wrong on the first query. the original issue. where it returns full set of data (expected) on watch
but then receives another emission for its network call, without cached data. which causes the UI to only show the first 5 items (rather than all 15, for example) and by paging down we then always have to requery more databod
09/14/2022, 2:48 PMCacheOnly
for the first one (so no network call, just observe the cache) and call the other one manually with page 1 when opening the screen?agrosner
09/15/2022, 5:14 PMagrosner
09/15/2022, 5:14 PMbod
09/15/2022, 5:32 PMagrosner
09/15/2022, 6:29 PM