Baris
Baris9mo ago

How can I make my queries more efficient

Hello everyone, first of all, Convex is an excellent backend and we loved it! We're still learning and trying to make queries more efficient and cost effective. Currently, We have a list that will contain thousands of items, and listing 50 items per page with a single query. But at the same time, each row uses its own useQuery to fetch additional data from a different table. Isn't it inefficient to use a useQuery for each row since each one counts as a function call? As a solution, Is it possible to return both row and additional data as a merged object or appending additional data to inside the row data like graphql?
6 Replies
jamwt
jamwt9mo ago
Yep! Your query functions can perform aggregates, or dependent subqueries (akin to SQL joins), and then merge everything together before returning the result
erquhart
erquhart9mo ago
you wouldn't believe how much nested parallel joining you can do in one query and still be performant
Baris
BarisOP9mo ago
Oh, okay thanks! I guess i should watch some tutorials to learn more about joins
jamwt
jamwt9mo ago
Relationship Structures: Let's Talk About Schemas
In this post we’ll look at some patterns for structuring relationships in the Convex database.
jamwt
jamwt9mo ago
and then it points to high-performance helper libraries to reduce the amount of code you're having to write here: https://stack.convex.dev/functional-relationships-helpers
Database Relationship Helpers
Traverse database relationships in a readable, predictable, and debuggable way. Support for one-to-one, one-to-many, and many-to-many via utility func...
Baris
BarisOP9mo ago
Thanks Jamie. These are definitely going to help me a lot 👍

Did you find this page helpful?