Michal
Michal3mo ago

Don't see db results after mutation, but only after the action is done running.

I'm updating file a couple rows at a time. But even though I see a console log before mutation (which changes data) for every batch, i see results on frontend only after all batches and so the action has finished running.
6 Replies
Convex Bot
Convex Bot3mo ago
Thanks for posting in <#1088161997662724167>. Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets. - Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.) - Use search.convex.dev to search Docs, Stack, and Discord all at once. - Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI. - Avoid tagging staff unless specifically instructed. Thank you!
Michal
MichalOP3mo ago
export const handleBatches = internalAction({ args: { headers: v.array(v.string()), batches: v.array(v.array(v.array(v.string()))), resourceColumnIndex: v.number(), fileId: v.id("files"), actionType: ActionType, userId: v.optional(v.string()), profileSummarizationHeaderIndex: v.optional(v.number()), companyInfoHeaderIndex: v.optional(v.number()), offering: v.optional(v.string()), }, handler: async (ctx, args) => { try { await ctx.runMutation(internal.files.updateFileRecord, { fileId: args.fileId, headers: [ ...args.headers, getHeaderColumnNameFromActionType(args.actionType), ], actionType: args.actionType, actionValue: true, }); // Fetch the current rows from the database const file = await ctx.runQuery(internal.files.getFileInternal, { fileId: args.fileId, }); if (!file) throw new Error("File not found"); let currentRows = file.rows || []; for (let i = 0; i < args.batches.length; i++) { const batch = args.batches[i]; const updatedRows = await handleBatchEnhance({ batch, resourceColumnIndex: args.resourceColumnIndex, actionType: args.actionType, userId: args.userId, profileSummarizationHeaderIndex: args.profileSummarizationHeaderIndex, companyInfoHeaderIndex: args.companyInfoHeaderIndex, offering: args.offering, }); // Calculate the start index for the current batch const startIndex = i * BATCH_SIZE; // Update the current rows with the updated rows for the current batch currentRows = [ ...currentRows.slice(0, startIndex), ...updatedRows, ...currentRows.slice(startIndex + updatedRows.length), ]; console.log("updating data with updatedRows: ", updatedRows); // Update the database with the new current rows await ctx.runMutation(internal.files.updateFileRecord, { fileId: args.fileId, newRows: currentRows, }); } } catch (error) { console.log(error); } finally { await ctx.runMutation(internal.files.updateFileRecordActionRunning, { fileId: args.fileId, actionType: args.actionType, value: false, }); } }, });
ballingt
ballingt3mo ago
@Michal what do you mean by results, the return value of the action? Or are queries you are subscribed to on the client not updating while the mutations run?
Michal
MichalOP3mo ago
@ballingt Yeah queries do not update. So i want to see updated data on frontend after every batch which calls mutation, but now i see updates on frontend after all batches are done running.
ballingt
ballingt3mo ago
sounds pretty weird, do you see the same thing if you add a wait for ten seconds in the middle? Do you see the database changes in the dashboard?
Michal
MichalOP3mo ago
wow, so i just fixed it I think by writing code for something else with changing handleBatchEnhance function, and returning list of resources instead of list of rows with resources. It doesn't make sense to me to be honest. I will try to revert this code tomorrow and see what was wrong to hopefully give you more insight.

Did you find this page helpful?