MietzeKatze
MietzeKatze•2mo ago

What is the best way to register the amount of functions beeing called per user?

First I thought I made an extra column in the user table and incremented a counter there, but in a query i cant access the ctx.patch function. Then I thought about using actions, but then I wouldnt have the realtime update of a query and in the docs it says, I shouldnt call too many actions, because they slow down the server. Soooo what could I do ? 😇 Is there a way to access the logs maybe via a function and I could maybe once an hour count? Is there an event I could subscribe a function to ?
13 Replies
Convex Bot
Convex Bot•2mo ago
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!
Sara
Sara•2mo ago
I'm not 100% sure i understand your question but it sounds like you're looking for the rate Limiter
Convex
Rate Limiter
Define and use application-layer rate limits. Type-safe, transactional, fair, safe, and configurable sharding to scale.
Clever Tagline
Clever Tagline•5w ago
While you can't use ctx.patch from a query, you can kick off a scheduled function with ctx.runAfter. As for what that scheduled function does, you might use the Aggregate component to keep the count. The rate limiting that Sara mentioned might also be useful depending on how active you feel this count system might become.
MietzeKatze
MietzeKatzeOP•5w ago
this is exactly what i need, but it seems like in a query there is no scheduler, runAfter or alike ...
MietzeKatze
MietzeKatzeOP•5w ago
No description
MietzeKatze
MietzeKatzeOP•5w ago
And if I managed it via an action, it wouldnt have realtime update anymore 😇
Sara
Sara•5w ago
you can't run mutations in a query, use mutation instead
MietzeKatze
MietzeKatzeOP•5w ago
i need it to be like this
MietzeKatze
MietzeKatzeOP•5w ago
No description
Clever Tagline
Clever Tagline•5w ago
Hmmm...my memory failed me again. I could've sworn that you could schedule things from queries. You're trying to get a count of how many times each user triggers each function call, correct?
MietzeKatze
MietzeKatzeOP•5w ago
yes, and not only mutations but also querys
Clever Tagline
Clever Tagline•5w ago
Yeah, that's a tricky one. Nothing else is coming readily to mind that would work with queries. I gotta get to work, but I'll try to check back later.
MietzeKatze
MietzeKatzeOP•5w ago
thank you sir 🙂

Did you find this page helpful?