Query arguments issue?
Came across an interesting problem that I was hoping to get some help with.
Basically I have a query that receives a timestamp as an argument to control what information is returned. This argument will change in certain key situations.
I know the default Convex behavior is to create a new subscription for each set of arguments, but I don't want all these subscriptions active because those will consume too much data. Is there a way to close unwanted subscriptions?
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!
When the useQuery is unmounted (in the React sense), the subscription is dropped and Convex stops running it.
Are you okay with a new query running every time the timestamp arg changes? That's what's happening; it's replacing the queries at previous timestamps
It's fine running a new query. The problem is that all previous subscriptions for different timestamps are still active. Adding a console.log does print each previous timestamp. I don't really have the option to unmount the component.
The main thing I'm trying to address with this timestamp is that I need this function to return only what actually changed between calls, not just a full result object every time.
Oh okay. Well you can get more control of the subscription lifetime by using the underlying watchQuery method https://docs.convex.dev/api/classes/react.ConvexReactClient#watchquery
Class: ConvexReactClient | Convex Developer Hub
react.ConvexReactClient
Like
```
Hey @Lee!
We did end up going with watchQuery. It worked like a charm, thank you very much for your help 😁
That's awesome! If you want to write it up and share (maybe #show-and-tell ) , this sounds like an interesting pattern others could learn about
I didn’t know about this. Would love to see it @Lucas Couto!