Repository navigation
fix(data): stop rebuilding collation indexes on every startup - #419
Merged
omegascorp merged 1 commit intoOct 19, 2026
Merged
Conversation
MongoDB reports an index's collation fully expanded (every option plus the ICU
version), while code declares only the fields it sets, e.g. { locale: 'en',
strength: 2 }. The deep-equal comparison never matched, so every startup
dropped and rebuilt unchanged collation indexes, including the unique
users indexes on handle and emails.address. Compare only the collation
fields the code declares.
omegascorp
approved these changes
Oct 19, 2026
omegascorp
left a comment
Collaborator
There was a problem hiding this comment.
Looks good, thank you
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.
Fixes #420
Problem
On every startup,
createIndexesdrops and rebuilds any index declared with acollation, even when nothing changed. That includes the built-in uniqueusersindexes onhandleandemails.address.MongoDB's
listIndexesreports a collation fully expanded, with every option plus the ICUversion:{ locale: 'en', caseLevel: false, caseFirst: 'off', strength: 2, numericOrdering: false, alternate: 'non-ignorable', maxVariable: 'punct', normalization: false, backwards: false, version: '57.1' }
The code declares only
{ locale: 'en', strength: 2 }.isSameIndexDefinitiondeep-compares the two, so they never match and the index always looks stale.With the default
backgroundcreation mode, the drop runs under the lock and the rebuild runs later in the background. Until the rebuild finishes:emails.addressindex exists to prevent;You can check it on any existing app with
db.users.getIndexes().Fix
Compare only the collation fields the index declares (
isSameCollationinsrc/data/store.ts). All other index options are still compared exactly as before.Trade-off: removing a field from a declared collation (for example deleting
strengthto go back to the default) no longer triggers a rebuild on its own. Changing a declared field's value still does.Tests
Two new tests in
src/data/store.test.ts, following the existingcreateIndexesones:npm run lint:check,npm run format:checkandnpm run testall pass (116 files, 1388 tests).