evaluateLocalEntityIds function
- EntityGraph graph,
- String type,
- ListQuery query
Evaluate query against canonical entities and return ordered IDs only.
Keeping IDs as the result preserves normalization: callers join them back against EntityGraph at read time instead of caching entity copies.
Implementation
List<String> evaluateLocalEntityIds(
EntityGraph graph,
String type,
ListQuery query,
) {
final entries = graph
.entityIds(type)
.map((id) => (id: id, row: graph.readEntity(type, id)))
.where((entry) => entry.row != null)
.map((entry) => (id: entry.id, row: entry.row!))
.where((entry) => _matchesQuery(entry.row, query))
.toList();
final sorts = query.sort;
if (sorts != null && sorts.isNotEmpty) {
entries.sort((left, right) {
for (final sort in sorts) {
final compared = _compareValues(
left.row[sort.field],
right.row[sort.field],
);
if (compared != 0) {
return sort.direction == SortDirection.asc ? compared : -compared;
}
}
return left.id.compareTo(right.id);
});
}
final limit = query.limit;
final ids = entries.map((entry) => entry.id);
return List.unmodifiable(limit == null ? ids : ids.take(limit));
}