Index run_hash so admin hide/delete/search by hash is instant#579
Merged
Conversation
Looking a run up by hash (admin search, hide, delete) matched on the run_hash
field, which is unindexed, so every lookup was a full scan of the ~740k-doc runs
collection (seconds). _id is the hash for single-player runs and is indexed;
multiplayer runs carry a shared run_hash field. Add a sparse index on run_hash so
the $or: [{_id}, {run_hash}] lookup (from the hide/delete fix) is an index union
instead of a collection scan. Sparse because only multiplayer docs have the
field, so the index stays small.
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.
The admin "look up a run by hash → hide/delete" flow is slow (seconds) — hiding
e7ad725372d1af64"took forever."Cause: those operations match on the
run_hashfield, which is unindexed, so every lookup is a full collection scan of the ~740k-doc runs collection. (_idis the hash for single-player runs and is indexed; multiplayer runs carry a sharedrun_hashfield.)Fix: add a sparse index on
run_hash. With it, the$or: [{_id}, {run_hash}]lookup used by the hide/delete/search fix (#577) becomes an index union instead of a scan — instant. Sparse because only multiplayer docs have the field, so the index is small and cheap to build.One line, ruff clean. The index builds on startup via
_ensure_indexes(idempotent).Note: this + #577 both need the prod backend to actually deploy to take effect — the CI built the images but the deploy/restart step is separate and hasn't run, which is also why hiding is still slow and single-player hides don't stick on live right now.