From b6eff8a49f67753d7889e5d6aa6351a257dfe677 Mon Sep 17 00:00:00 2001 From: xmagda03 Date: Mon, 21 Sep 2026 15:27:23 +0200 Subject: [PATCH 1/2] fix(api): sort by _id instead of last.eid for eid pseudo-attribute 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. --- dp3/api/routers/entity.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/dp3/api/routers/entity.py b/dp3/api/routers/entity.py index ccddcc27..9924ac8e 100644 --- a/dp3/api/routers/entity.py +++ b/dp3/api/routers/entity.py @@ -432,8 +432,13 @@ async def get_entity_type_eids( # Apply sorting if specified if sort_criteria: - # Prepare sort specification with 'last.' prefix for snapshot data - sort_spec = [("last." + attr, direction) for attr, direction in sort_criteria] + # 'eid' is a pseudo-attribute: for binary-eid collections the _id prefix + # is the packed EID, so sorting by _id matches entity order. + # All other attributes live under 'last.' + sort_spec = [ + ("_id" if attr == "eid" else "last." + attr, direction) + for attr, direction in sort_criteria + ] cursor = cursor.sort(sort_spec) cursor_page = cursor.skip(skip).limit(limit) From b26f803fb61a83a26591470f147849bd3dab6107 Mon Sep 17 00:00:00 2001 From: Ondrej Sedlacek Date: Mon, 21 Sep 2026 17:13:12 +0200 Subject: [PATCH 2/2] docs: clarify sort behavior --- dp3/api/routers/entity.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/dp3/api/routers/entity.py b/dp3/api/routers/entity.py index 9924ac8e..1c33ac35 100644 --- a/dp3/api/routers/entity.py +++ b/dp3/api/routers/entity.py @@ -432,9 +432,10 @@ async def get_entity_type_eids( # Apply sorting if specified if sort_criteria: - # 'eid' is a pseudo-attribute: for binary-eid collections the _id prefix - # is the packed EID, so sorting by _id matches entity order. - # All other attributes live under 'last.' + # 'eid' uses snapshot _id storage order so standalone EID sorts can use + # the _id index. This intentionally differs from natural EID order for + # some strings (bucket suffixes) and signed integers (binary encoding). + # Other attributes live under 'last.' sort_spec = [ ("_id" if attr == "eid" else "last." + attr, direction) for attr, direction in sort_criteria