Skip to content

Commit 0bbc355

Browse files
committed
fix: get child ids for folder in a separate query during move
Signed-off-by: Robin Appelman <[email protected]>
1 parent 20953d0 commit 0bbc355

1 file changed

Lines changed: 22 additions & 3 deletions

File tree

lib/private/Files/Cache/Cache.php

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -687,10 +687,14 @@ public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) {
687687
throw new \Exception('Invalid target storage id: ' . $targetStorageId);
688688
}
689689

690-
$this->connection->beginTransaction();
691690
if ($sourceData['mimetype'] === 'httpd/unix-directory') {
692691
//update all child entries
693692
$sourceLength = mb_strlen($sourcePath);
693+
694+
$childIds = $this->getChildIds($sourceStorageId, $sourcePath);
695+
696+
$childChunks = array_chunk($childIds, 1000);
697+
694698
$query = $this->connection->getQueryBuilder();
695699

696700
$fun = $query->func();
@@ -703,19 +707,25 @@ public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) {
703707
->set('path_hash', $fun->md5($newPathFunction))
704708
->set('path', $newPathFunction)
705709
->where($query->expr()->eq('storage', $query->createNamedParameter($sourceStorageId, IQueryBuilder::PARAM_INT)))
706-
->andWhere($query->expr()->like('path', $query->createNamedParameter($this->connection->escapeLikeParameter($sourcePath) . '/%')));
710+
->andWhere($query->expr()->in('fileid', $query->createParameter('files')));
707711

708712
// when moving from an encrypted storage to a non-encrypted storage remove the `encrypted` mark
709713
if ($sourceCache->hasEncryptionWrapper() && !$this->hasEncryptionWrapper()) {
710714
$query->set('encrypted', $query->createNamedParameter(0, IQueryBuilder::PARAM_INT));
711715
}
712716

713717
try {
714-
$query->execute();
718+
$this->connection->beginTransaction();
719+
foreach ($childChunks as $chunk) {
720+
$query->setParameter('files', $chunk, IQueryBuilder::PARAM_INT_ARRAY);
721+
$query->execute();
722+
}
715723
} catch (\OC\DatabaseException $e) {
716724
$this->connection->rollBack();
717725
throw $e;
718726
}
727+
} else {
728+
$this->connection->beginTransaction();
719729
}
720730

721731
$query = $this->getQueryBuilder();
@@ -751,6 +761,15 @@ public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) {
751761
}
752762
}
753763

764+
private function getChildIds(int $storageId, string $path): array {
765+
$query = $this->connection->getQueryBuilder();
766+
$query->select('fileid')
767+
->from('filecache')
768+
->where($query->expr()->eq('storage', $query->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)))
769+
->andWhere($query->expr()->like('path', $query->createNamedParameter($this->connection->escapeLikeParameter($path) . '/%')));
770+
return $query->executeQuery()->fetchAll(\PDO::FETCH_COLUMN);
771+
}
772+
754773
/**
755774
* remove all entries for files that are stored on the storage from the cache
756775
*/

0 commit comments

Comments
 (0)