ianI
Convex Community3y ago
5 replies
ian

Performance impact of re-using queries

@erquhart : I'm handling authorization by creating reusable queries that ensure authorization for the data they return, and each of them reuse this query:
export const getUser = async (auth: Auth, db: DatabaseReader) => {
  const identity = await auth.getUserIdentity()
  if (!identity) {
    throw new Error('Not authenticated')
  }
  const user = await db
    .query('users')
    .withIndex('byClerkId', (q) => q.eq('clerkId', identity.subject))
    .unique()
  if (!user) {
    throw new Error('User not found')
  }
  return user
}


I don't know much about Convex's runtime, would a lot of identical calls to queries like this be expected to impact response times?
Was this page helpful?