Keep paginated query from growing with new items
I have a paginated query that in the client I retrieve with usePaginatedQuery. The problem is whenever there's new items the results array grows with items I don't want to show at that point. Right now I am filtering out those new items in the client using the _creationTime of the first item that I have kept. This works but the results in the paginated query hook state keep growing unnecessarily.
What is the recommended way of solving this? I have asked the docs AI and it has recommended using a timestamp and retrieving only items older than that. I can run another query for items newer than the timestamp to know if there are new items too. If I want to do that I need to generate the timestamp in the backend with another query because doing it in the frontend could be problematic, right? Is there a better way to solve all this that I'm missing?
8 Replies
Thanks for posting in <#1088161997662724167>.
Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets.
- Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.)
- Use search.convex.dev to search Docs, Stack, and Discord all at once.
- Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI.
- Avoid tagging staff unless specifically instructed.
Thank you!
You can pass in a timestamp as an arg to your query and use it to exclude those items in your query definition.
I first have to make a query to get the timestamp from the backend, right? Generating it on the frontend would be problematic if the system clock of the user is wrong for whatever reason.
Yeah that's true, can't think of a great way around that
so you don't want additions, but you want deletions and edits right
yeah you have to somehow capture client side state to anchor the query, fetching a timestamp (or less hacky, run the same query you're paginating but do
.first() instead of .paginate(), and use _creationTime from that record) is how I'd approach that if you need pagination specificallyIdeally only edits
Oh, that's a good one, using first
Ideally only editsAh this would still include deletions
I know but I can handle that on the frontend
Thanks for your help
np!