Skip to content

⚡ Optimize Google Sheets Webhook with Bulk Inserts for Post Keywords - #86

Open
Sparkier wants to merge 1 commit into
mainfrom
performance/google-sheets-webhook-bulk-insert-9277142641453024454
Open

⚡ Optimize Google Sheets Webhook with Bulk Inserts for Post Keywords#86
Sparkier wants to merge 1 commit into
mainfrom
performance/google-sheets-webhook-bulk-insert-9277142641453024454

Conversation

@Sparkier

@Sparkier Sparkier commented Aug 1, 2026

Copy link
Copy Markdown
Owner

🎯 What
Optimized the Google Sheets webhook endpoint by removing the N+1 database queries when associating keywords to newly inserted posts. postkeyword relation objects are now gathered into an array during iteration and inserted via a single bulk insert operation 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.ts processing 2000 mock rows:

  • Baseline: ~113-115ms (using in-memory Vitest mocks for Supabase client)
  • Optimized: ~63-80ms (using same mocks)

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

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>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@vercel

vercel Bot commented Aug 1, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
vis-positions Ready Ready Preview Aug 1, 2026 11:23am

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant