Implementing a virtual waiting room
I was thinking I could use a mutation to add users when they open the website and use the ‘by_creation’ index but not sure how to 1) efficiently query their position in line and 2) boot inactive users (e.g. if they leave the site).
Perhaps I could have each client "listen" to the front of the queue (i.e.
order('asc').first()) and respond accordingly if their ID matches it. If I have a global counter, I can add a field to the schema that stores the counter value at time of insertion with each user in the queue. Then, the difference between the user's value and the front of the queue's value is the user's position in line.Not sure how to drop users from the queue if they leave the site. Maybe I keep a heartbeat timestamp for each user in the queue? I noticed there was some discussion about sendBeacon and presence earlier.
Anyways, do you think Convex is the right tool for this use case? Do you have a simpler proposal?
I'm using Vercel/NextJS with API routes + Planetscale + Clerk right now. I will also need Expo/RN support.
