Conversation
Rules and synonyms are imported in batches of 1000. The clear flag was attached only to the request sent when the buffer filled, so the final partial batch was saved without it. For any file holding fewer than 1000 entries there is no full batch at all, so the only request sent carried no flag and --clear-existing-rules / --replace-existing-synonyms did nothing. The existing ClearRules/ClearSynonyms fallback does not cover this: it is guarded by totalCount == 0, so it only fires for an empty input file. The flag is attached only when it is still set, so a multi-batch import's later requests keep omitting the parameter rather than sending clearExistingRules=false, preserving the current wire format. Fixes algolia#191 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Duplication | 10 |
TIP This summary will be updated as you push new changes.
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.
Summary
Fixes #191.
algolia rules import --clear-existing-rules(andalgolia synonyms import --replace-existing-synonyms) silently does nothing for any input file under 1000 entries — which is nearly all of them.Both commands import in batches of 1000. In
pkg/cmd/rules/import/import.go, the clear flag is only attached to theSaveRulesrequest in the batch-full path:The final partial batch calls
SaveRuleswith no clear flag at all:A file under 1000 rules never fills the buffer, so this final call is the only
SaveRulesrequest sent — and it drops the flag. The existingClearRulesfallback is guarded bytotalCount == 0, so it only helps for an empty input file, not a small non-empty one.pkg/cmd/synonyms/import/import.gohas the identical defect:WithReplaceExistingSynonymsis attached in the batch-full path but not the tail block.Fix
Pass the flag to the final batch's request too, conditioned on whether it hasn't already been consumed by an earlier full batch — this keeps the wire format unchanged for multi-batch imports (a later request still omits the parameter rather than sending
clearExistingRules=false).Test plan
pkg/cmd/rules/import/import_test.goandpkg/cmd/synonyms/import/import_test.goasserting the outgoing request carries the flag when set, and omits it when notmainand pass with the fixgo build ./...,go vet ./...cleango test ./...— no new regressions (pre-existing Windows-path test failures in a handful ofimport/operations/updatepackages are unchanged by this diff, and unrelated to it)🤖 Generated with Claude Code