what is the fastest way to clear a table with 1m+ rows
claude suggested a batch process which is also very slow:
export const clearTableBatch = mutation({
args: { batchSize: v.optional(v.number()) },
handler: async (ctx, { batchSize = 100 }) => {
const documents = await ctx.db
.query("your_table_name")
.take(batchSize);
for (const doc of documents) {
await ctx.db.delete(doc._id);
}
return {
deleted: documents.length,
hasMore: documents.length === batchSize
};
},
});
what is the recommended way?
