Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable28] get child ids for folder in a separate query during move #45850

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions lib/private/Files/Cache/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,11 @@ public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) {
if ($sourceData['mimetype'] === 'httpd/unix-directory') {
//update all child entries
$sourceLength = mb_strlen($sourcePath);

$childIds = $this->getChildIds($sourceStorageId, $sourcePath);

$childChunks = array_chunk($childIds, 1000);

$query = $this->connection->getQueryBuilder();

$fun = $query->func();
Expand All @@ -714,7 +719,7 @@ public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) {
->set('path_hash', $fun->md5($newPathFunction))
->set('path', $newPathFunction)
->where($query->expr()->eq('storage', $query->createNamedParameter($sourceStorageId, IQueryBuilder::PARAM_INT)))
->andWhere($query->expr()->like('path', $query->createNamedParameter($this->connection->escapeLikeParameter($sourcePath) . '/%')));
->andWhere($query->expr()->in('fileid', $query->createParameter('files')));

// when moving from an encrypted storage to a non-encrypted storage remove the `encrypted` mark
if ($sourceCache->hasEncryptionWrapper() && !$this->hasEncryptionWrapper()) {
Expand All @@ -727,12 +732,17 @@ public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) {
for ($i = 1; $i <= $retryLimit; $i++) {
try {
$this->connection->beginTransaction();
$query->executeStatement();
foreach ($childChunks as $chunk) {
$query->setParameter('files', $chunk, IQueryBuilder::PARAM_INT_ARRAY);
$query->executeStatement();
}
break;
} catch (\OC\DatabaseException $e) {
$this->connection->rollBack();
throw $e;
} catch (DbalException $e) {
$this->connection->rollBack();

if (!$e->isRetryable()) {
throw $e;
}
Expand All @@ -742,8 +752,6 @@ public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) {
throw $e;
}

$this->connection->rollBack();

// Sleep a bit to give some time to the other transaction to finish.
usleep(100 * 1000 * $i);
}
Expand Down Expand Up @@ -785,6 +793,15 @@ public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) {
}
}

private function getChildIds(int $storageId, string $path): array {
$query = $this->connection->getQueryBuilder();
$query->select('fileid')
->from('filecache')
->where($query->expr()->eq('storage', $query->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)))
->andWhere($query->expr()->like('path', $query->createNamedParameter($this->connection->escapeLikeParameter($path) . '/%')));
return $query->executeQuery()->fetchAll(\PDO::FETCH_COLUMN);
}

/**
* remove all entries for files that are stored on the storage from the cache
*/
Expand Down
Loading