Skip to content

fix(rank-tracking): batch bulk keyword deletes to stay under D1's bound-parameter limit - #179

Open
redrammedia wants to merge 1 commit into
every-app:mainfrom
redrammedia:fix/d1-bulk-delete-batching
Open

fix(rank-tracking): batch bulk keyword deletes to stay under D1's bound-parameter limit#179
redrammedia wants to merge 1 commit into
every-app:mainfrom
redrammedia:fix/d1-bulk-delete-batching

Conversation

@redrammedia

Copy link
Copy Markdown

Problem

Selecting many keywords in rank tracking and deleting them at once fails with a generic "An unexpected error occurred" toast. The server log shows:

D1_ERROR: too many SQL variables at offset 378: SQLITE_ERROR
    at Object.removeKeywordsFromConfig ...

removeKeywordsFromConfig builds a single DELETE ... WHERE id IN (...) with one bound parameter per keyword id. D1 caps bound parameters at ~100 per statement, so deleting more than ~100 selected keywords always fails (reproduced with 670 keywords on a self-hosted Docker install). Deleting a few keywords works, which makes the failure look intermittent to users.

Fix

Route the delete through the existing executeInBatches helper (one delete per id, batched atomically in chunks of 100), exactly like addKeywordsToConfig and updateKeywordMetrics already do in the same file. The sibling snapshot queries already chunk for the same reason (snapshotQueries.ts uses CHUNK_SIZE = 90); the delete path was the one remaining unbatched bulk operation.

Testing

  • pnpm ci:check, pnpm test:ci, pnpm vite build all pass.
  • Manually verified on a self-hosted Docker install (D1/SQLite): deleting 670 selected keywords now succeeds; single deletes unchanged.

🤖 Generated with Claude Code

…nd-parameter limit

Deleting many keywords at once built a single DELETE ... WHERE id IN (...)
with one bound parameter per keyword, which fails on D1 with 'too many SQL
variables' beyond ~100 selected keywords. Use executeInBatches like the
insert/update paths already do.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
HasimEmre pushed a commit to HasimEmre/open-seo that referenced this pull request Jul 30, 2026
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