Skip to content

fix(api): sort by _id instead of last.eid for eid pseudo-attribute - #47

Open
JakubMagda wants to merge 2 commits into
masterfrom
fix/eid-sort-timeout
Open

JakubMagda wants to merge 2 commits into
masterfrom
fix/eid-sort-timeout

Conversation

@JakubMagda

Copy link
Copy Markdown
Collaborator

Summary

Fixes timeouts when sorting entity lists (/{etype}/get) by the eid pseudo-attribute without any filter.

Problem

The eid sort field was blindly mapped to last.eid like 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 eid pseudo-attribute to _id in the sort specification. The _id prefix is the entity ID itself, so the ordering is identical while the sort becomes backed by the primary key.

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.
@JakubMagda
JakubMagda requested a review from xsedla1o September 21, 2026 13:31

@xsedla1o xsedla1o left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants