Starlord
Starlord•4mo ago

pagination and caching

So what's the point of this argument? Bite the dust and accept the 2x bills?
76 Replies
jamwt
jamwt•4mo ago
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
Starlord
StarlordOP•4mo ago
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
jamwt
jamwt•4mo ago
so, same query, no mutations, no caching?
Starlord
StarlordOP•4mo ago
its query only and i wrote ticket 24 ago with no response
Barrel Of Lube
Barrel Of Lube•4mo ago
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.
v
v•4mo ago
jamie is basically the king of this topic
Starlord
StarlordOP•4mo ago
i know about client side caching has nothing to do with it here
jamwt
jamwt•4mo ago
well, I actually haven't worked on the caching guts of the databasde in awhile but we have people that know it well
v
v•4mo ago
wow
jamwt
jamwt•4mo ago
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
v
v•4mo ago
sounds bad
jamwt
jamwt•4mo ago
yep
v
v•4mo ago
how much less do cached queries cost? its only the bandwidth or more
Starlord
StarlordOP•4mo ago
i tried everything no caching at all on paginated queries and huge db consumtion
v
v•4mo ago
ill do some test rn
Starlord
StarlordOP•4mo ago
my bill jumped from 25 to 90 usd with shrinking userbase
v
v•4mo ago
big baller
jamwt
jamwt•4mo ago
okay. yeah, that sounds crazy will look
v
v•4mo ago
is it the same exact code
Starlord
StarlordOP•4mo ago
yes small update to db structure only i had peak active users when i had 25 usd bill
jamwt
jamwt•4mo ago
can you dm me your team slug name? that way we can dig into your specific account and try to find this issue
Starlord
StarlordOP•4mo ago
the only thing that changed is there are more documents in the database but that what paginated querie is there for sure
v
v•4mo ago
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
jamwt
jamwt•4mo ago
this is with no auth, I take it? just regular ol paginated query on a table?
v
v•4mo ago
yes
jamwt
jamwt•4mo ago
got it. yeah that seems bad will get some people looking into this thanks
v
v•4mo ago
No description
v
v•4mo ago
i even tried on convex 18 i guess it doesnt matter maybe that doesn't work the way i thought
jamwt
jamwt•4mo ago
yeah, this is surprising. we'll look into it this should be cached
v
v•4mo ago
w jamie as always and a very good report from starlord
sneakyf1shy
sneakyf1shy•4mo ago
so right now, is there no way to use this with pagination?
Barrel Of Lube
Barrel Of Lube•4mo ago
they are retrieving the data server side it seems so client side caching is of no use
sneakyf1shy
sneakyf1shy•4mo ago
sorta got the "hover cache" working with the query-caching helper
Starlord
StarlordOP•4mo ago
after multiple tests here is conclusion: query.paginate(paginationOpts) call invalidates cache of the query
Starlord
StarlordOP•4mo ago
i ended up writing own pagination solution that solved the problem with caching
No description
No description
Starlord
StarlordOP•4mo ago
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
sneakyf1shy
sneakyf1shy•4mo ago
can you send these as codeblocks?
Starlord
StarlordOP•4mo ago
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.
Starlord
StarlordOP•4mo ago
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
jamwt
jamwt•4mo ago
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.
jamwt
jamwt•4mo ago
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
v
v•4mo ago
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
Starlord
StarlordOP•4mo ago
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)
v
v•4mo ago
Any update on this ? @Starlord have you seen any improvements Still using own pagination? Wonder what's up with that
Starlord
StarlordOP•4mo ago
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
v
v•4mo ago
Rip Would put me in bankruptcy Not literally but type shit I'll test it again Maybe try to see the sync data
Starlord
StarlordOP•4mo ago
the problem before was with paginate serverside call idk if it was fixed
v
v•4mo ago
I tried using the older convex version and didn't see any fixed one
Starlord
StarlordOP•4mo ago
well for sure in some older version this issue was not there it came 1-2 month ago its about server side not client
v
v•4mo ago
Maybe hosted convex doesn't actually use an older backend
Starlord
StarlordOP•4mo ago
hosted convex gets updated
v
v•4mo ago
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
Starlord
StarlordOP•4mo ago
if only index would be more flexible would not even need paginate implementation
jamwt
jamwt•4mo ago
sorry, just to correct here -- we linked in another thread. the issue is client side, not server
jamwt
jamwt•4mo ago
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.
jamwt
jamwt•4mo ago
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
v
v•4mo ago
I could be wrong but I don't believe this to be correct
jamwt
jamwt•4mo ago
which part?
v
v•4mo ago
I tested without any react code whatsoever And starlord has fixed the issue with the incrementing id .
jamwt
jamwt•4mo ago
ah okay. thanks for the clarification. I'll sync up with ian and make sure we know that when we investigated
v
v•4mo ago
yeeeeeeeep just tested again and it seems any time paginate is called it just will not cache what so ever
jamwt
jamwt•4mo ago
yep, confirmed. sorry folks okay I have my own project too same deal will escalate
v
v•4mo ago
🔥
jamwt
jamwt•4mo ago
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
v
v•4mo ago
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
Starlord
StarlordOP•4mo ago
thanks. would it be possible to decrease my last bill because of this bug? 🙂
jamwt
jamwt•4mo ago
will follow up on your ticket 🙂
Starlord
StarlordOP•4mo ago
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
jamwt
jamwt•4mo ago
yeah both are issues
ian
ian•4mo ago
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.
v
v•4mo ago
poor cache never busting again
Starlord
StarlordOP•4mo ago
Please inform us when we can use also server side pagination. Thanks
v
v•4mo ago
@jamwt so you fixed it without telling us huh i forgive you
jamwt
jamwt•4mo ago
Fixed!
v
v•4mo ago
😂 Very nice
Starlord
StarlordOP•4mo ago
thanks

Did you find this page helpful?