fix(api): sort by _id instead of last.eid for eid pseudo-attribute - #47
Open
JakubMagda wants to merge 2 commits into
Open
JakubMagda wants to merge 2 commits into
JakubMagda wants to merge 2 commits into
Conversation
Sorting entity lists by the pseudo-attribute eid was mapped to last.eid, forcing an in-memory sort over all latest snapshots and causing timeouts on unfiltered queries. Sort by _id instead - its EID prefix yields the same entity order.
xsedla1o
approved these changes
Sep 21, 2026
xsedla1o
left a comment
Collaborator
There was a problem hiding this comment.
Note this breaks exact ordering for string and integer eid types. "a0" now comes before "a" and 0 is now before -1.
Due to the perf improvements I think this tradeoff is acceptable, just want it documented here.
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 timeouts when sorting entity lists (
/{etype}/get) by theeidpseudo-attribute without any filter.Problem
The
eidsort field was blindly mapped tolast.eidlike any other attribute. That field cannot be used for sorting efficiently, so an unfiltered sorted query had to load and sort every latest snapshot, leading to timeouts. With a filter applied the result set was small enough to sort, which is why sorting only appeared broken on unfiltered queries.Fix
Map the
eidpseudo-attribute to_idin the sort specification. The_idprefix is the entity ID itself, so the ordering is identical while the sort becomes backed by the primary key.