From 670e5c7d5224f0e150b6403d93fd872ec3414166 Mon Sep 17 00:00:00 2001 From: Christoph Fiehe Date: Tue, 10 Sep 2024 23:06:43 +0200 Subject: [PATCH 1/2] Fix slow move on same object bucket during file upload. This commit fixes the issue https://github.com/nextcloud/server/issues/47856. When you upload a file into a group folder and when you use a single S3 bucket as primary storage, the final move operation hangs for a long time. In the background, Nextcloud initiates a copy-delete sequence from the bucket into the bucket, with causes a lot unnecessary overhead. Nextcloud thinks that the file must be imported to another storage and does not recognize that everything is done on the same object bucket. In that case, the import step can be completely skipped, which saves time, network bandwidth and reduces the load on the object storage. Signed-off-by: Christoph Fiehe --- lib/Mount/GroupFolderStorage.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/Mount/GroupFolderStorage.php b/lib/Mount/GroupFolderStorage.php index 36c0df4bb..aa607ee34 100644 --- a/lib/Mount/GroupFolderStorage.php +++ b/lib/Mount/GroupFolderStorage.php @@ -69,4 +69,14 @@ public function getScanner($path = '', $storage = null) { } return $storage->scanner; } + + public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) { + if ($sourceStorage->instanceOfStorage(ObjectStoreStorage::class) && + $this->instanceOfStorage(ObjectStoreStorage::class) && + $sourceStorage->getObjectStore()->getStorageId() == $this->getObjectStore()->getStorageId()) { + // Do not import any data when source and target object storages are identical. + return true; + } + return parent::moveFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); + } } From e7b6f2c8e33958703f1691febeec1f8641f496ea Mon Sep 17 00:00:00 2001 From: cfiehe Date: Wed, 11 Sep 2024 07:18:27 +0200 Subject: [PATCH 2/2] Update lib/Mount/GroupFolderStorage.php Agreed. Doing the comparison with the `===` operator is better, because it is stricter. Thank you very much for the suggestion. Co-authored-by: Ferdinand Thiessen Signed-off-by: cfiehe --- lib/Mount/GroupFolderStorage.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/Mount/GroupFolderStorage.php b/lib/Mount/GroupFolderStorage.php index aa607ee34..9ac86585e 100644 --- a/lib/Mount/GroupFolderStorage.php +++ b/lib/Mount/GroupFolderStorage.php @@ -11,6 +11,7 @@ use OC\Files\ObjectStore\ObjectStoreStorage; use OC\Files\Storage\Wrapper\Quota; use OCP\Files\Cache\ICacheEntry; +use OCP\Files\Storage\IStorage; use OCP\IUser; use OCP\IUserSession; @@ -73,9 +74,9 @@ public function getScanner($path = '', $storage = null) { public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) { if ($sourceStorage->instanceOfStorage(ObjectStoreStorage::class) && $this->instanceOfStorage(ObjectStoreStorage::class) && - $sourceStorage->getObjectStore()->getStorageId() == $this->getObjectStore()->getStorageId()) { - // Do not import any data when source and target object storages are identical. - return true; + $sourceStorage->getObjectStore()->getStorageId() === $this->getObjectStore()->getStorageId()) { + // Do not import any data when source and target object storages are identical. + return true; } return parent::moveFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); }