meowcat_32
meowcat_32•3d ago

Filter size limit

const documents = posts.slice(0, 50);
console.log(JSON.stringify(documents).length); // 37472
await client.mutation(api.tasks.upsertPost, { documents });
const documents = posts.slice(0, 50);
console.log(JSON.stringify(documents).length); // 37472
await client.mutation(api.tasks.upsertPost, { documents });
export const upsertPost = mutation({
args: { documents: v.array(schema.tables.posts.validator) },
handler: async (ctx, { documents }) => {
await Promise.all(
documents.map(async (doc) => {
const existing = await ctx.db
.query('posts')
.filter((q) => q.eq(q.field('id'), doc.id))
.first();
if (existing) {
return ctx.db.replace(existing._id, doc);
} else {
return ctx.db.insert('posts', doc);
}
})
);
}
});
export const upsertPost = mutation({
args: { documents: v.array(schema.tables.posts.validator) },
handler: async (ctx, { documents }) => {
await Promise.all(
documents.map(async (doc) => {
const existing = await ctx.db
.query('posts')
.filter((q) => q.eq(q.field('id'), doc.id))
.first();
if (existing) {
return ctx.db.replace(existing._id, doc);
} else {
return ctx.db.insert('posts', doc);
}
})
);
}
});
[CONVEX M(tasks:upsertPost)] [Request ID: 557f3142a6cb7f0b] Server Error
Uncaught Error: Too many bytes read in a single function execution (limit: 8388608 bytes). Consider using smaller limits in your queries, paginating your queries, or using indexed queries with a selective index range expressions.
at async <anonymous> (../convex/tasks.ts:13:15)
at async Promise.all (index 0)all [as all] (<anonymous>)
at async handler (../convex/tasks.ts:7:18)
[CONVEX M(tasks:upsertPost)] [Request ID: 557f3142a6cb7f0b] Server Error
Uncaught Error: Too many bytes read in a single function execution (limit: 8388608 bytes). Consider using smaller limits in your queries, paginating your queries, or using indexed queries with a selective index range expressions.
at async <anonymous> (../convex/tasks.ts:13:15)
at async Promise.all (index 0)all [as all] (<anonymous>)
at async handler (../convex/tasks.ts:7:18)
why am i getting that error, its not even 50kb 😦
1 Reply
lee
lee•3d ago
Documents excluded by .filter still count as being read, for the purposes of limits and bandwidth. I would recommend using an index to look up posts by id

Did you find this page helpful?