Billing question regarding counting function calls....
Hi guys, I have a little question regarding what is counted as function call. This would influence how I design a few things in my app
Question 1: if I call queries or mutations from the FE, they are counted towoards the function calls. correct? (thi is more or less a sanity check)
....
Lets assume I have the following:
query: getTodo (id:string)
- this will get a dodo from db
query: getMultipleTodos(ids: string[])
- return ids.map(id => cts.runQuery(getTodo(id))
basically, getMultipleTodos will call getTodo multiple times, but this is in the convex folder, in the query def.
case 1: if I iterate over the todo ids in FE and I call getTodo for each one (N times) => this si counted as N function calls?
case2: I call getMultipleTodos from FE. This will generate multiple queries in the "be". Is this counted as 1 function call or as N+1 calls?
I am asking because this would affect the way code is shared in the BE, because I can extract the ctx.db.get from the getTodo and reuse it in both getTodo and getMultipleTodos in order to avoid hitting cts.runQuery
Thanks
4 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!
up 😄
Case 1:
If you call getTodo for each ID from the frontend (so
N
separate calls), this will result in N
function calls: one for each query you make from the client.
Case 2:
1 function call for getMultipleTodos (from the FE)
N
additional function calls for each ctx.runQuery(getTodo, { id })
inside the backend
So basically N+1
function calls
You should use a typescript function instead of creating a seperate query!!!
Please us #ask-ai when you need help and you think that AI might solve it.thanks! 🚀