β‘ perf: optimize push scheduler cron to run queries in parallel#15
β‘ perf: optimize push scheduler cron to run queries in parallel#15marcin2121 wants to merge 1 commit into
Conversation
Resolves N+1 query issue in the push scheduler cron by using `Promise.all` to fetch subscriptions and send web pushes concurrently. Replaces sequential `.update().eq()` calls with a single bulk `.in()` status update. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@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: The push scheduler cron logic in
app/api/cron/push-scheduler/route.tswas optimized to execute database queries and push notification tasks in parallel, and bulk update history rows.π― Why: Previously, the cron iterated sequentially over each scheduled push, creating an N+1 query bottleneck as it fetched subscriptions, sent pushes, and updated the status row-by-row.
π Measured Improvement: In a local benchmark simulation of 10 pushes (
test_perf.js), the parallel execution reduced total time from ~1007 ms to ~101 ms, achieving a ~10x performance improvement for 10 scheduled pushes.Additionally, added a protective check before calling the
.in('id', pushIds)bulk update to avoid a400 Bad Requestif the array happens to be empty.PR created automatically by Jules for task 10424595588112908456 started by @marcin2121