⚡ Optimize Google Sheets Webhook with Bulk Inserts for Post Keywords - #86
⚡ Optimize Google Sheets Webhook with Bulk Inserts for Post Keywords#86Sparkier wants to merge 1 commit into
Conversation
This commit resolves an N+1 query issue in the Google Sheets webhook endpoint. Instead of calling Supabase's `insert()` inside the processing loop for every post's keywords, we now accumulate all relations into an array and perform a single bulk insert operation after the loop completes. This reduces the number of database queries scaling linearly with the number of processed rows with keywords to a single constant overhead query, which significantly improves latency. Co-authored-by: Sparkier <5690524+Sparkier@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. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🎯 What
Optimized the Google Sheets webhook endpoint by removing the N+1 database queries when associating keywords to newly inserted posts.
postkeywordrelation objects are now gathered into an array during iteration and inserted via a single bulkinsertoperation after the loop.📊 Coverage
Tests are green. This logic is covered by the existing webhook unit tests (
src/routes/api/webhooks/google-sheets/server.test.ts), which were successfully ran.✨ Result
Measured via the existing benchmark script
src/routes/api/webhooks/google-sheets/perf.test.tsprocessing 2000 mock rows:The overhead reduction is noticeable even with mock objects. In a real-world scenario with network roundtrips to the Supabase Postgres instance, skipping hundreds or thousands of individual HTTP requests for the N+1
insert()queries will yield massive latency and DB load improvements.PR created automatically by Jules for task 9277142641453024454 started by @Sparkier