adrianhajdin / podcastr

https://podcastr-23zf.vercel.app
456 stars 89 forks source link

Error: [CONVEX Q(users:getTopUserByPodcastCount)] #4

Open Jay-Karia opened 1 month ago

Jay-Karia commented 1 month ago

Server Error Uncaught Error: Too many bytes read in a single function execution (limit: 8388608 bytes).

image

ldanilek commented 2 weeks ago

To avoid this error, you can add an index on the podcasts table by authorId, and use it here https://github.com/adrianhajdin/podcastr/blob/e4b647350223c45e2ebee356112158545d61473e/convex/users.ts#L31

const podcasts = await ctx.db
          .query("podcasts")
          .withIndex("by_authorId", (q) => q.eq("authorId", u.clerkId))
          .collect();

and define the index here https://github.com/adrianhajdin/podcastr/blob/e4b647350223c45e2ebee356112158545d61473e/convex/schema.ts#L21

.index("by_authorId", ["authorId"])

Why this works: with a .filter(), it reads the entire podcasts table for each user, but withIndex only looks up the podcasts authored by that specific user.