Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add yieldEntities wrapper for entity mapping in QBMapper #45947

Merged
merged 1 commit into from
Jun 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions lib/public/AppFramework/Db/QBMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
namespace OCP\AppFramework\Db;

use Generator;
use OCP\DB\Exception;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
Expand Down Expand Up @@ -321,6 +322,26 @@ protected function findEntities(IQueryBuilder $query): array {
}
}

/**
* Runs a sql query and yields each resulting entity to obtain database entries in a memory-efficient way
*
* @param IQueryBuilder $query
* @return Generator Generator of fetched entities
* @psalm-return Generator<T> Generator of fetched entities
* @throws Exception
* @since 30.0.0
*/
protected function yieldEntities(IQueryBuilder $query): Generator {
$result = $query->executeQuery();
try {
while ($row = $result->fetch()) {
nickvergessen marked this conversation as resolved.
Show resolved Hide resolved
yield $this->mapRowToEntity($row);
}
} finally {
$result->closeCursor();
}
nickvergessen marked this conversation as resolved.
Show resolved Hide resolved
}


/**
* Returns an db result and throws exceptions when there are more or less
Expand Down
Loading