Skip to content

Commit 0f493e7

Browse files
committed
fix: get child ids for folder in a separate query during move
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent 35d0c63 commit 0f493e7

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
@@ -695,10 +695,14 @@ public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) {
695695
throw new \Exception('Invalid target storage id: ' . $targetStorageId);
696696
}
697697

698-
$this->connection->beginTransaction();
699698
if ($sourceData['mimetype'] === 'httpd/unix-directory') {
700699
//update all child entries
701700
$sourceLength = mb_strlen($sourcePath);
701+
702+
$childIds = $this->getChildIds($sourceStorageId, $sourcePath);
703+
704+
$childChunks = array_chunk($childIds, 1000);
705+
702706
$query = $this->connection->getQueryBuilder();
703707

704708
$fun = $query->func();
@@ -711,19 +715,25 @@ public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) {
711715
->set('path_hash', $fun->md5($newPathFunction))
712716
->set('path', $newPathFunction)
713717
->where($query->expr()->eq('storage', $query->createNamedParameter($sourceStorageId, IQueryBuilder::PARAM_INT)))
714-
->andWhere($query->expr()->like('path', $query->createNamedParameter($this->connection->escapeLikeParameter($sourcePath) . '/%')));
718+
->andWhere($query->expr()->in('fileid', $query->createParameter('files')));
715719

716720
// when moving from an encrypted storage to a non-encrypted storage remove the `encrypted` mark
717721
if ($sourceCache->hasEncryptionWrapper() && !$this->hasEncryptionWrapper()) {
718722
$query->set('encrypted', $query->createNamedParameter(0, IQueryBuilder::PARAM_INT));
719723
}
720724

721725
try {
722-
$query->execute();
726+
$this->connection->beginTransaction();
727+
foreach ($childChunks as $chunk) {
728+
$query->setParameter('files', $chunk, IQueryBuilder::PARAM_INT_ARRAY);
729+
$query->execute();
730+
}
723731
} catch (\OC\DatabaseException $e) {
724732
$this->connection->rollBack();
725733
throw $e;
726734
}
735+
} else {
736+
$this->connection->beginTransaction();
727737
}
728738

729739
$query = $this->getQueryBuilder();
@@ -759,6 +769,15 @@ public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) {
759769
}
760770
}
761771

772+
private function getChildIds(int $storageId, string $path): array {
773+
$query = $this->connection->getQueryBuilder();
774+
$query->select('fileid')
775+
->from('filecache')
776+
->where($query->expr()->eq('storage', $query->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)))
777+
->andWhere($query->expr()->like('path', $query->createNamedParameter($this->connection->escapeLikeParameter($path) . '/%')));
778+
return $query->executeQuery()->fetchAll(\PDO::FETCH_COLUMN);
779+
}
780+
762781
/**
763782
* remove all entries for files that are stored on the storage from the cache
764783
*/

0 commit comments

Comments
 (0)