]> source.dussan.org Git - nextcloud-server.git/commitdiff
use a generator instead of fetching all rows at once
authorRobin Appelman <robin@icewind.nl>
Wed, 12 Jul 2017 11:37:42 +0000 (13:37 +0200)
committerRobin Appelman <robin@icewind.nl>
Thu, 13 Jul 2017 11:08:24 +0000 (13:08 +0200)
Signed-off-by: Robin Appelman <robin@icewind.nl>
lib/private/Repair/NC13/RepairInvalidPaths.php

index 076fbb735c8ee605d458614cc34fed5029c73880..47a007baf5ffdbfcfe4546deafb463e0d0a72f1e 100644 (file)
@@ -60,7 +60,10 @@ class RepairInvalidPaths implements IRepairStep {
                        ))
                        ->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) {
@@ -103,8 +106,11 @@ class RepairInvalidPaths implements IRepairStep {
        }
 
        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
@@ -114,7 +120,8 @@ class RepairInvalidPaths implements IRepairStep {
                                $this->update($entry['fileid'], $calculatedPath);
                        }
                }
-               return count($entries);
+               $this->connection->commit();
+               return $count;
        }
 
        public function run(IOutput $output) {