refactor: nodeList generator
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user