#Query bandwidth seems off

8 messages · Page 1 of 1 (latest)

tropic pivot
#

Hi! Just getting started with Convex for a small side project and I'm a bit surprised with the query bandwidth being used for such few operations.

  1. When I try and check bandwidth usage per function the table is blank (screenshot attached) I assume this is a bug.

  2. Is there a way to optimise bandwidth besides indexes? we have a lot of permission checks so queries calling queries and I suspect that's racking up the bandwidth, would be good to understand how caching comes into play here.

For example, this gets called on almost every query:

export const checkWorkspaceAccess = query({
  args: {
    workspaceId: v.id('workspaces')
  },
  handler: async (ctx, args) => {
    const userId = await getAuthUserId(ctx)
    if (!userId) throw new Error('Not authenticated')

    const userWorkspace = await ctx.db
      .query('userWorkspaces')
      .withIndex('by_workspace', q => q.eq('workspaceId', args.workspaceId))
      .filter(q => q.eq(q.field('userId'), userId))
      .first()

    if (!userWorkspace) throw new Error('Not authorized')
    return { hasAccess: true, userId }
  }
})

Is this recommended and is there a better practice?

dire kite
#
  1. how long has the project existed? There may be some delay in usage metrics, since they're accumulated in a separate database.

  2. the main way to reduce bandwidth is with indexes (the other way is to do fewer queries). Your code looks like it could use an index on ["workspaceId", "userId"] (.filter is not good if you're optimizing)

tropic pivot
#
  1. Project is around a month old

  2. Thanks for the multi index suggestion, I'll give that a go

tropic pivot
#

What do you mean by fewer queries? Is there a way to configure that? Or do you mean just optimising the number of calls to the database?

dire kite
#

I mean optimizing the number of calls to the database.

#

Idk why usage wouldn't show up for a month-old project. Maybe @eager thunder would know?

eager thunder
#

Heya, we’ll investigate the bandwidth being off today. To help investigate, could you #verify your account or dm me the email address associated with your account?

eager thunder
#

We found and fixed the bug! You should see the database bandwidth breakdown by function now. Thanks for the report