pagination and caching
So what's the point of this argument? Bite the dust and accept the 2x bills?
76 Replies
happy to talk through paging + caching strategies--but so you know, you can always go back to manual page management like traditional databases if you don't want to use convex's automatic pagination
using something like the aggregate module
if you want the full control, you can have it. you just don't get automatic reactive page management
what kind of aggregate module is it and where do i find it
caching on paginated queries got worse there is 0 caching right now
i am not only one who complains about data bandwith consumtion
so, same query, no mutations, no caching?
its query only and i wrote ticket 24 ago with no response
https://www.npmjs.com/package/convex-helpers#query-caching does this help?
npm
convex-helpers
A collection of useful code to complement the official convex package.. Latest version: 0.1.87, last published: a day ago. Start using convex-helpers in your project by running
npm i convex-helpers
. There are 13 other projects in the npm registry using convex-helpers.jamie is basically the king of this topic
i know about client side caching has nothing to do with it here
well, I actually haven't worked on the caching guts of the databasde in awhile
but we have people that know it well
wow
we have sites at a lot of scale that go down without caching... so normally if there's a blip, we hear about it fast from our big customers.
but its still entirely possible we have a regression
so happy to take a look
no mutations, two queries in a row, no caching is what I'm hearing
on a paginated query
that does sound wrong
sounds bad
yep
how much less do cached queries cost? its only the bandwidth or more
i tried everything no caching at all on paginated queries and huge db consumtion
ill do some test rn
my bill jumped from 25 to 90 usd
with shrinking userbase
big baller
okay. yeah, that sounds crazy
will look
is it the same exact code
yes
small update to db structure only
i had peak active users when i had 25 usd bill
can you dm me your team slug name? that way we can dig into your specific account and try to find this issue
the only thing that changed is there are more documents in the database but that what paginated querie is there for
sure
do you think more than 5mb
i ask just because im going to run some test
purely for my own curiosity
yeah they are not caching for me either
this is with no auth, I take it? just regular ol paginated query on a table?
yes
got it. yeah that seems bad
will get some people looking into this
thanks

i even tried on convex 18
i guess it doesnt matter
maybe that doesn't work the way i thought
yeah, this is surprising. we'll look into it
this should be cached
w jamie as always and a very good report from starlord
so right now, is there no way to use this with pagination?
they are retrieving the data server side it seems so client side caching is of no use
sorta got the "hover cache" working with the query-caching helper
after multiple tests here is conclusion: query.paginate(paginationOpts) call invalidates cache of the query
i ended up writing own pagination solution that solved the problem with caching


also one more thing that invalidates all the cache of entire app = any change to the code of anything in convex
it should not happen and kind of stupid. it should invalidate cache only of affected functions
can you send these as codeblocks?
Pastebin
const { numItems, cursor: cursorString } = paginationOpts;const num...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
but beware this is for my products table
also my client pagination code is slightly modified and default may not accept isdone parameter but hasMore
but now i see its not very good solution and is working because query did not hit document limit yet. its operates on filter to instead of index because index is not possible here
okay, confirmed with the team. the issue isn't the backend, but it is the pagination hook: https://github.com/get-convex/convex-js/blob/main/src/react/use_paginated_query.ts#L180
GitHub
convex-js/src/react/use_paginated_query.ts at main · get-convex/co...
TypeScript/JavaScript client library for Convex. Contribute to get-convex/convex-js development by creating an account on GitHub.
this incrementing id essentially makes it so paginated queries are never cacheable. chatting with the team to see if there are some solutions available. but this has always been the case as long as this hook has existed
hm interesting for sure. i didnt even use react for my test and still nothing got cached
No this would still cache for different users
But I guess I don't know his query
So maybe it's the same user
That's causing the increase
But either way I didn't provide id, and still no cache
@Jamie
Maybe I'm a dummy
not true. i am using own hook that has id 0 always. i have seen already this problem and fixed it back than myself. but now this is new problem
i debuged and server side paginate is causing the problem with caching. but i fixed it temporary for myself by writing own paginate solution (using index + filter + custom cursor)
Any update on this ?
@Starlord have you seen any improvements
Still using own pagination?
Wonder what's up with that
yes using own. i did not see any info that convex fixed it
and i had 100 usd bill instead of 25 for last month
Rip
Would put me in bankruptcy
Not literally but type shit
I'll test it again
Maybe try to see the sync data
the problem before was with paginate serverside call idk if it was fixed
I tried using the older convex version and didn't see any fixed one
well for sure in some older version this issue was not there
it came 1-2 month ago
its about server side not client
Maybe hosted convex doesn't actually use an older backend
hosted convex gets updated
I see that it knows my convex version but maybe it's cross compatible and still uses the updated version
Who knows
Hope it gets fixed for ya
if only index would be more flexible would not even need paginate implementation
sorry, just to correct here -- we linked in another thread. the issue is client side, not server
the react hook has an incrementing number that busts the cache: https://github.com/get-convex/convex-js/blob/main/src/react/use_paginated_query.ts#L180
GitHub
convex-js/src/react/use_paginated_query.ts at main · get-convex/co...
TypeScript/JavaScript client library for Convex. Contribute to get-convex/convex-js development by creating an account on GitHub.
ian provided some links to alternative implementations that fix this
(cc @Ian)
indexes are ordered btrees, so it's difficult to know what you mean by "more flexible". they work just like classic RDBMSes -- in fact, they are just MySQL indexes
I could be wrong but I don't believe this to be correct
which part?
I tested without any react code whatsoever
And starlord has fixed the issue with the incrementing id
.
ah okay. thanks for the clarification. I'll sync up with ian and make sure we know that when we investigated
yeeeeeeeep just tested again and it seems any time paginate is called it just will not cache what so ever
yep, confirmed. sorry folks
okay
I have my own project too
same deal
will escalate
🔥
yeah it's fucked
lol
okay
we'll look ASAP
not sure what happened here
@Starlord apologize, looks like you're 100% right
we'll figure out what's up
Lol fucked
Made me lol
Well I have no idea what's the issue I looked at the backend code and frankly there's just too much for a little brain
thanks. would it be possible to decrease my last bill because of this bug? 🙂
will follow up on your ticket 🙂
thanks
but for clarification id changing in react library breaks caching too. so i have set it already long time ago for me to 0
yeah both are issues
fwiw I updated the
usePaginatedQuery
from the client caching provider helper to not include the cache busting parameter, so the query can hopefully stay live client-side to help out.poor cache never busting again
Please inform us when we can use also server side pagination. Thanks
@jamwt so you fixed it without telling us huh
i forgive you
Fixed!
😂
Very nice
thanks