refactor: nodeList generator

Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
2026-09-04 20:56:51 -04:00
parent 4d589fff31
commit 8e98e0749a
3 changed files with 75 additions and 17 deletions
+7 -5
View File
@@ -531,9 +531,11 @@ class MetaStore {
// ========== Node Operations (Unified/Recursive) ==========
/**
* List all nodes (collections and entities)
* Lazily yield nodes from the database cursor, keyed by identifier.
*
* @return \Generator<string|int,CollectionResource|EntityResource>
*/
public function nodeList(string $tenantId, string $userId, string|int|null $location = null, bool $recursive = false, ?Filter $filter = null, ?Sort $sort = null, ?IRange $range = null): array {
public function nodeList(string $tenantId, string $userId, string|int|null $location = null, bool $recursive = false, ?Filter $filter = null, ?Sort $sort = null, ?IRange $range = null): \Generator {
$query = [
'tid' => $tenantId,
'uid' => $userId,
@@ -573,17 +575,17 @@ class MetaStore {
}
$cursor = $this->_store->selectCollection($this->_NodeTable)->find($query, $options);
$list = [];
foreach ($cursor as $entry) {
$nodeType = $entry['type'];
if ($nodeType === NodeType::Collection->value) {
$node = (new CollectionResource())->fromStore($entry);
} else if ($nodeType === NodeType::Entity->value) {
$node = (new EntityResource())->fromStore($entry);
} else {
continue;
}
$list[$node->identifier()] = $node;
yield $node->identifier() => $node;
}
return $list;
}
/**