Is it possible to listen for subscribe/unsubscribe events for queries and trigger an action?
For example, for a convex query like api.messages.list, I want to be able to query the users who are listening to it at that time. I can update the lastOnline value for each user periodically and track it with this, but this will cause an absurd number of function calls. Since the client connects to the backend via websocket, this information is actually available in the backend. But I couldn't find how to access it and trigger an action in case of disconnect.
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!
not the way you describe, but here's an article on the pattern: https://stack.convex.dev/presence-with-convex
Implementing Presence with Convex
Some patterns for incorporating presence into a web app leveraging Convex, and sharing some tips & utilities I built along the way.
Yes, this is the same logic as updating the lastOnline value. Currently we have an application with 10k clients on supabase and their online status needs to be monitored 24/7. Since api call is unlimited in Supabase, such a heartbeat style solution is not a problem. But it would cause extra cost in convex.
how did you solve this issue???
by not using convex 🙂
I even made my own socket tunnel to save bandwidth and function calls... and somehow, Convex still owns my heart 😂
love youu convex 💖
it can't be unlimited? what's to stop me or someone abusing it with a million live status updates?
API requests are unlimited in supabase. There may be a cost only due to bandwidth consumption.
There is already a hardware resource allocated to you. It doesn't matter if you use it 24/7 or not. In my application, currently 2m api requests (Client -> PostgREST) go to the database weekly and CPU usage is ~8% (1GB Ram, 2 ARM CPU)
convex is very cool but for now I only use it in my hobby projects 🙂