Skip to content

Commit

Permalink
perf: improve performance of SharedStorage::getWatcher
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Appelman <robin@icewind.nl>

[skip ci]
  • Loading branch information
icewind1991 authored and backportbot[bot] committed Dec 3, 2024
1 parent 0c32d38 commit 4cd4890
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions apps/files_sharing/lib/SharedStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
namespace OCA\Files_Sharing;

use OC\Files\Cache\CacheDependencies;
use OC\Files\Cache\CacheEntry;
use OC\Files\Cache\FailedCache;
use OC\Files\Cache\NullWatcher;
use OC\Files\Cache\Watcher;
Expand All @@ -17,7 +18,6 @@
use OC\Files\Storage\Wrapper\PermissionsMask;
use OC\Files\Storage\Wrapper\Wrapper;
use OC\User\NoUserException;
use OCA\Files_External\Config\ConfigAdapter;
use OCA\Files_Sharing\ISharedStorage as LegacyISharedStorage;
use OCP\Constants;
use OCP\Files\Cache\ICacheEntry;
Expand Down Expand Up @@ -456,17 +456,13 @@ public function getWatcher($path = '', $storage = null): Watcher {

// Get node information
$node = $this->getShare()->getNodeCacheEntry();
if ($node) {
/** @var IUserMountCache $userMountCache */
$userMountCache = \OC::$server->get(IUserMountCache::class);
$mounts = $userMountCache->getMountsForStorageId($node->getStorageId());
foreach ($mounts as $mount) {
// If the share is originating from an external storage
if ($mount->getMountProvider() === ConfigAdapter::class) {
// Propagate original storage scan
$this->watcher = parent::getWatcher($path, $storage);
return $this->watcher;
}
if ($node instanceof CacheEntry) {
$storageId = $node->getData()['storage_string_id'];
// for shares from the home storage we can rely on the home storage to keep itself up to date
// for other storages we need use the proper watcher
if (!(str_starts_with($storageId, 'home::') || str_starts_with($storageId, 'object::user'))) {
$this->watcher = parent::getWatcher($path, $storage);
return $this->watcher;
}
}

Expand Down

0 comments on commit 4cd4890

Please sign in to comment.