Repository navigation
fix(events): replace repetitions groupHash_hashed index with groupHashAndId - #692
Merged
Merged
Conversation
Reversean
requested changes
Nov 19, 2026
Kuchizu
approved these changes
Nov 19, 2026
Kuchizu
left a comment
Member
There was a problem hiding this comment.
Heavy migration for a single-node DB, let's run it off-peak.
Reversean
approved these changes
Nov 20, 2026
alisawavezen12
approved these changes
Nov 20, 2026
neSpecc
added a commit
that referenced
this pull request
Nov 20, 2026
…hAndId (#692) (#693) * fix(events): replace repetitions groupHash_hashed index with groupHashAndId * Bump version up to 1.7.1 * fix(migrations): simplify IndexNotFound error check * chore(migrations): add progress logging for repetitions index migration --------- Co-authored-by: Peter <specc.dev@gmail.com> Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
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: slow query LatestRepetitions
How to reproduce:
Fixes: https://garage.hawk.so/project/5ee3bb8531ad69816c67e035/event/6aff16f9960f464d87f7f097/6aff173fb78a9e93012b84e2/overview
Reason
query LatestRepetitions(Event.repetitionsPortion->EventsFactory.getEventRepetitions) queriesrepetitions:<projectId>with:Because
repetitions:<projectId>only had{ groupHash: 'hashed' }(groupHash_hashed) and{ groupHash: 1, release: 1 }(groupHashAndRelease), MongoDB had no index covering bothgroupHashequality and_id: -1ordering/range. As a result, queries fell back to either scanning_idbackwards across unrelated events or fetching all repetitions for agroupHashand performing a blocking in-memory sort — taking 4–20s on large collections.Solution
groupHash_hashedwith a compound B-tree index{ groupHash: 1, _id: -1 }(groupHashAndId) onrepetitions:<projectId>increateProject(src/resolvers/project.js).migrations/20261119000000-replace-repetition-group-hash-index.jsfor existingrepetitions:*collections: it createsgroupHashAndIdfirst (sogroupHashqueries remain indexed with zero downtime) and then dropsgroupHash_hashed.test/resolvers/project.test.tsto verifygroupHashAndIdis created andgroupHash_hashedis not.Why
groupHash_hashedcan be safely removedgroupHashis the leading prefix of the new{ groupHash: 1, _id: -1 }B-tree index, so MongoDB can usegroupHashAndIdfor any exactgroupHashlookup (e.g.,deleteMany({ groupHash })inremoveEvent) while also supporting_idsorting and cursor range scans (_id: { $lte: cursor }) — which a hashed index cannot do. Nothing in the codebase hintsgroupHash_hashed(whilegroupHashAndReleaseis preserved forrelease-validator).