aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2024-02-12 15:52:07 +0100
committerMarcel Klehr <mklehr@gmx.net>2024-06-11 09:01:06 +0200
commitd4cfe32c57bf9ef2050972af8f4dda92a19fa1b4 (patch)
tree6f9fe43a21098ebc625642ef71ae9ee9977e2d2a
parent3024d71f1b2a0e63fbd7a2a91db6fcbbfa1e39dd (diff)
downloadnextcloud-server-patch/performance-scckit.tar.gz
nextcloud-server-patch/performance-scckit.zip
fix: get child ids for folder in a separate query during movepatch/performance-scckit
Signed-off-by: Robin Appelman <robin@icewind.nl>
-rw-r--r--lib/private/Files/Cache/Cache.php32
1 files changed, 24 insertions, 8 deletions
diff --git a/lib/private/Files/Cache/Cache.php b/lib/private/Files/Cache/Cache.php
index 9822b6874f9..21c039b3cca 100644
--- a/lib/private/Files/Cache/Cache.php
+++ b/lib/private/Files/Cache/Cache.php
@@ -708,6 +708,11 @@ class Cache implements ICache {
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();
@@ -720,7 +725,7 @@ class Cache implements ICache {
->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()) {
@@ -731,13 +736,15 @@ class Cache implements ICache {
// Retry up to 4 times because we should receive up to 4 concurrent requests from the frontend
$retryLimit = 4;
for ($i = 1; $i <= $retryLimit; $i++) {
- try {
- $this->connection->beginTransaction();
- $query->executeStatement();
- break;
- } catch (\OC\DatabaseException $e) {
- $this->connection->rollBack();
- throw $e;
+ try {
+ $this->connection->beginTransaction();
+ foreach ($childChunks as $chunk) {
+ $query->setParameter('files', $chunk, IQueryBuilder::PARAM_INT_ARRAY);
+ $query->execute();
+ }
+ } catch (\OC\DatabaseException $e) {
+ $this->connection->rollBack();
+ throw $e;
} catch (RetryableException $e) {
// Simply throw if we already retried 4 times.
if ($i === $retryLimit) {
@@ -787,6 +794,15 @@ class Cache implements ICache {
}
}
+ 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
*/