summaryrefslogtreecommitdiffstats
path: root/lib/private/Repair
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2017-07-13 19:30:05 +0200
committerGitHub <noreply@github.com>2017-07-13 19:30:05 +0200
commit01466ab8403c9f1fb1f2a92490bbf1be82db0a43 (patch)
treee93e18d086771244bad7bd177fc78c6368f85881 /lib/private/Repair
parente335121d5ead8b8a223ca12212529c2230bc1c5d (diff)
parent350e036c56d1ddd60e8a8d6d8822dbf8979f8719 (diff)
downloadnextcloud-server-01466ab8403c9f1fb1f2a92490bbf1be82db0a43.tar.gz
nextcloud-server-01466ab8403c9f1fb1f2a92490bbf1be82db0a43.zip
Merge pull request #5715 from nextcloud/master-5655
Fixed repair step
Diffstat (limited to 'lib/private/Repair')
-rw-r--r--lib/private/Repair/NC13/RepairInvalidPaths.php91
1 files changed, 66 insertions, 25 deletions
diff --git a/lib/private/Repair/NC13/RepairInvalidPaths.php b/lib/private/Repair/NC13/RepairInvalidPaths.php
index 076fbb735c8..cf0b9e7783e 100644
--- a/lib/private/Repair/NC13/RepairInvalidPaths.php
+++ b/lib/private/Repair/NC13/RepairInvalidPaths.php
@@ -22,17 +22,25 @@
namespace OC\Repair\NC13;
+use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
class RepairInvalidPaths implements IRepairStep {
+ const MAX_ROWS = 1000;
+
/** @var IDBConnection */
private $connection;
/** @var IConfig */
private $config;
+ private $getIdQuery;
+ private $updateQuery;
+ private $reparentQuery;
+ private $deleteQuery;
+
public function __construct(IDBConnection $connection, IConfig $config) {
$this->connection = $connection;
$this->config = $config;
@@ -58,53 +66,85 @@ class RepairInvalidPaths implements IRepairStep {
$builder->expr()->eq('f.parent', 'p.fileid'),
$builder->expr()->neq('p.name', $builder->createNamedParameter(''))
))
- ->where($builder->expr()->neq('f.path', $computedPath));
-
- return $query->execute()->fetchAll();
+ ->where($builder->expr()->neq('f.path', $computedPath))
+ ->setMaxResults(self::MAX_ROWS);
+
+ do {
+ $result = $query->execute();
+ $rows = $result->fetchAll();
+ foreach ($rows as $row) {
+ yield $row;
+ }
+ $result->closeCursor();
+ } while (count($rows) >= self::MAX_ROWS);
}
private function getId($storage, $path) {
- $builder = $this->connection->getQueryBuilder();
+ if (!$this->getIdQuery) {
+ $builder = $this->connection->getQueryBuilder();
- $query = $builder->select('fileid')
- ->from('filecache')
- ->where($builder->expr()->eq('storage', $builder->createNamedParameter($storage)))
- ->andWhere($builder->expr()->eq('path', $builder->createNamedParameter($path)));
+ $this->getIdQuery = $builder->select('fileid')
+ ->from('filecache')
+ ->where($builder->expr()->eq('storage', $builder->createParameter('storage')))
+ ->andWhere($builder->expr()->eq('path', $builder->createParameter('path')));
+ }
+
+ $this->getIdQuery->setParameter('storage', $storage, IQueryBuilder::PARAM_INT);
+ $this->getIdQuery->setParameter('path', $path);
- return $query->execute()->fetchColumn();
+ return $this->getIdQuery->execute()->fetchColumn();
}
private function update($fileid, $newPath) {
- $builder = $this->connection->getQueryBuilder();
+ if (!$this->updateQuery) {
+ $builder = $this->connection->getQueryBuilder();
+
+ $this->updateQuery = $builder->update('filecache')
+ ->set('path', $builder->createParameter('newpath'))
+ ->set('path_hash', $builder->func()->md5($builder->createParameter('newpath')))
+ ->where($builder->expr()->eq('fileid', $builder->createParameter('fileid')));
+ }
- $query = $builder->update('filecache')
- ->set('path', $builder->createNamedParameter($newPath))
- ->set('path_hash', $builder->createNamedParameter(md5($newPath)))
- ->where($builder->expr()->eq('fileid', $builder->createNamedParameter($fileid)));
+ $this->updateQuery->setParameter('newpath', $newPath);
+ $this->updateQuery->setParameter('fileid', $fileid, IQueryBuilder::PARAM_INT);
- $query->execute();
+ $this->updateQuery->execute();
}
private function reparent($from, $to) {
- $builder = $this->connection->getQueryBuilder();
+ if (!$this->reparentQuery) {
+ $builder = $this->connection->getQueryBuilder();
+
+ $this->reparentQuery = $builder->update('filecache')
+ ->set('parent', $builder->createParameter('to'))
+ ->where($builder->expr()->eq('fileid', $builder->createParameter('from')));
+ }
+
+ $this->reparentQuery->setParameter('from', $from);
+ $this->reparentQuery->setParameter('to', $to);
- $query = $builder->update('filecache')
- ->set('parent', $builder->createNamedParameter($to))
- ->where($builder->expr()->eq('fileid', $builder->createNamedParameter($from)));
- $query->execute();
+ $this->reparentQuery->execute();
}
private function delete($fileid) {
- $builder = $this->connection->getQueryBuilder();
+ if (!$this->deleteQuery) {
+ $builder = $this->connection->getQueryBuilder();
+
+ $this->deleteQuery = $builder->delete('filecache')
+ ->where($builder->expr()->eq('fileid', $builder->createParameter('fileid')));
+ }
+
+ $this->deleteQuery->setParameter('fileid', $fileid, IQueryBuilder::PARAM_INT);
- $query = $builder->delete('filecache')
- ->where($builder->expr()->eq('fileid', $builder->createNamedParameter($fileid)));
- $query->execute();
+ $this->deleteQuery->execute();
}
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 +154,8 @@ class RepairInvalidPaths implements IRepairStep {
$this->update($entry['fileid'], $calculatedPath);
}
}
- return count($entries);
+ $this->connection->commit();
+ return $count;
}
public function run(IOutput $output) {