Skip to content

Commit

Permalink
use a generator instead of fetching all rows at once
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Appelman <robin@icewind.nl>
  • Loading branch information
icewind1991 committed Jul 13, 2017
1 parent 64d0a0f commit 95e17a8
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/private/Repair/NC13/RepairInvalidPaths.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ private function getInvalidEntries() {
))
->where($builder->expr()->neq('f.path', $computedPath));

return $query->execute()->fetchAll();
$result = $query->execute();
while ($row = $result->fetch()) {
yield $row;
}
}

private function getId($storage, $path) {
Expand Down Expand Up @@ -103,8 +106,11 @@ private function delete($fileid) {
}

private function repair() {
$this->connection->beginTransaction();
$entries = $this->getInvalidEntries();
$count = 0;
foreach ($entries as $entry) {
$count++;
$calculatedPath = $entry['parent_path'] . '/' . $entry['name'];
if ($newId = $this->getId($entry['storage'], $calculatedPath)) {
// a new entry with the correct path has already been created, reuse that one and delete the incorrect entry
Expand All @@ -114,7 +120,8 @@ private function repair() {
$this->update($entry['fileid'], $calculatedPath);
}
}
return count($entries);
$this->connection->commit();
return $count;
}

public function run(IOutput $output) {
Expand Down

0 comments on commit 95e17a8

Please sign in to comment.