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
Yep! Your query functions can perform aggregates, or dependent subqueries (akin to SQL joins), and then merge everything together before returning the result
you wouldn't believe how much nested parallel joining you can do in one query and still be performant
Oh, okay thanks! I guess i should watch some tutorials to learn more about joins
@Baris this is a good starting point: https://stack.convex.dev/relationship-structures-let-s-talk-about-schemas
Relationship Structures: Let's Talk About Schemas
In this post we’ll look at some patterns for structuring relationships in the Convex database.
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...
Thanks Jamie. These are definitely going to help me a lot 👍