fix(rank-tracking): batch bulk keyword deletes to stay under D1's bound-parameter limit - #179
Open
redrammedia wants to merge 1 commit into
Open
fix(rank-tracking): batch bulk keyword deletes to stay under D1's bound-parameter limit#179redrammedia wants to merge 1 commit into
redrammedia wants to merge 1 commit into
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
removeKeywordsFromConfigbuilds a singleDELETE ... 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
executeInBatcheshelper (one delete per id, batched atomically in chunks of 100), exactly likeaddKeywordsToConfigandupdateKeywordMetricsalready do in the same file. The sibling snapshot queries already chunk for the same reason (snapshotQueries.tsusesCHUNK_SIZE = 90); the delete path was the one remaining unbatched bulk operation.Testing
pnpm ci:check,pnpm test:ci,pnpm vite buildall pass.🤖 Generated with Claude Code