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
+5 -12
View File
@@ -334,7 +334,7 @@ class PersonalService implements ServiceBaseInterface, ServiceCollectionMutableI
// If not forcing, ensure the collection is empty
if (!$force) {
$children = $this->metaStore->nodeList($this->serviceTenantId, $this->serviceUserId, $identifier, false);
if (!empty($children)) {
if ($children->valid()) {
throw new InvalidParameterException("Collection is not empty: $identifier");
}
}
@@ -808,18 +808,11 @@ class PersonalService implements ServiceBaseInterface, ServiceCollectionMutableI
// Node operations (unified collections + entities)
public function nodeList(string|int|null $location, ?IFilter $filter = null, ?ISort $sort = null, ?IRange $range = null): array {
public function nodeList(string|int|null $location, ?IFilter $filter = null, ?ISort $sort = null, ?IRange $range = null): Generator {
$location = $this->normalizeLocation($location);
$entries = $this->metaStore->nodeList($this->serviceTenantId, $this->serviceUserId, $location, false, $filter, $sort, $range);
// cache nodes
foreach ($entries as $id => $node) {
if ($node instanceof CollectionResource) {
$this->serviceCollectionCache[$id] = $node;
} elseif ($node instanceof EntityResource) {
$this->serviceEntityCache[$id] = $node;
}
}
return $entries;
// Do not retain yielded nodes in the service caches: large consumers must
// be able to release each node as they advance through the cursor.
yield from $this->metaStore->nodeList($this->serviceTenantId, $this->serviceUserId, $location, false, $filter, $sort, $range);
}
public function nodeListFilter(): IFilter {