⚡ Optimize N+1 queries in mutations#3
Conversation
Co-authored-by: singhaditya21 <53948039+singhaditya21@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
💡 What:
saveAttendance,markClassAttendance, andenterMarksinapps/web/src/lib/actions/mutations.ts.await db.select()...loop with a single batched query using Drizzle'sinArray().toInsertandtoUpdatecollections based on the batched existing records fetch.db.insert()query for new records and an array of concurrentdb.update()queries usingPromise.allfor existing records.db.transaction(async (tx) => { ... })to guarantee consistency and atomicity.🎯 Why:
SELECT+INSERT/UPDATE) for every element in an array sequentially. This caused significant execution slowdowns for moderately sized bulk operations (e.g., submitting attendance for an entire classroom of students or entering all exam marks simultaneously).📊 Measured Improvement:
PR created automatically by Jules for task 10462716342378686815 started by @singhaditya21