diff options
author | Carl Schwan <carl@carlschwan.eu> | 2022-04-21 16:31:19 +0200 |
---|---|---|
committer | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2022-04-22 15:22:16 +0200 |
commit | 3d49fe473a934c3fc9e17afadba3cbddd423603d (patch) | |
tree | ffa0dd81a7fbf214fb9611af1ef8e5842cb04ed2 /apps/files_sharing/lib | |
parent | efde83e07f3d5474326334008755cba4b13fa6ee (diff) | |
download | nextcloud-server-3d49fe473a934c3fc9e17afadba3cbddd423603d.tar.gz nextcloud-server-3d49fe473a934c3fc9e17afadba3cbddd423603d.zip |
Cache display name
This should saves some query in the share backend when displaying the
owner and it's not important if the display name is 10 minutes outdated
as it is very rare that this gets changed.
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
Diffstat (limited to 'apps/files_sharing/lib')
-rw-r--r-- | apps/files_sharing/lib/Cache.php | 31 | ||||
-rw-r--r-- | apps/files_sharing/lib/SharedStorage.php | 4 |
2 files changed, 13 insertions, 22 deletions
diff --git a/apps/files_sharing/lib/Cache.php b/apps/files_sharing/lib/Cache.php index 8729426221b..3482a9fc71a 100644 --- a/apps/files_sharing/lib/Cache.php +++ b/apps/files_sharing/lib/Cache.php @@ -33,6 +33,7 @@ use OC\Files\Cache\Wrapper\CacheJail; use OC\Files\Search\SearchBinaryOperator; use OC\Files\Search\SearchComparison; use OC\Files\Storage\Wrapper\Jail; +use OC\User\DisplayNameCache; use OCP\Files\Cache\ICacheEntry; use OCP\Files\Search\ISearchBinaryOperator; use OCP\Files\Search\ISearchComparison; @@ -46,27 +47,22 @@ use OCP\IUserManager; * don't use this class directly if you need to get metadata, use \OC\Files\Filesystem::getFileInfo instead */ class Cache extends CacheJail { - /** @var \OCA\Files_Sharing\SharedStorage */ + /** @var SharedStorage */ private $storage; - /** @var ICacheEntry */ - private $sourceRootInfo; - /** @var IUserManager */ - private $userManager; - - private $rootUnchanged = true; - - private $ownerDisplayName; - - private $numericId; + private ICacheEntry $sourceRootInfo; + private bool $rootUnchanged = true; + private ?string $ownerDisplayName = null; + private int $numericId; + private DisplayNameCache $displayNameCache; /** - * @param \OCA\Files_Sharing\SharedStorage $storage + * @param SharedStorage $storage */ - public function __construct($storage, ICacheEntry $sourceRootInfo, IUserManager $userManager) { + public function __construct($storage, ICacheEntry $sourceRootInfo, DisplayNameCache $displayNameCache) { $this->storage = $storage; $this->sourceRootInfo = $sourceRootInfo; - $this->userManager = $userManager; $this->numericId = $sourceRootInfo->getStorageId(); + $this->displayNameCache = $displayNameCache; parent::__construct( null, @@ -173,12 +169,7 @@ class Cache extends CacheJail { private function getOwnerDisplayName() { if (!$this->ownerDisplayName) { $uid = $this->storage->getOwner(''); - $user = $this->userManager->get($uid); - if ($user) { - $this->ownerDisplayName = $user->getDisplayName(); - } else { - $this->ownerDisplayName = $uid; - } + $this->ownerDisplayName = $this->displayNameCache->getDisplayName($uid); } return $this->ownerDisplayName; } diff --git a/apps/files_sharing/lib/SharedStorage.php b/apps/files_sharing/lib/SharedStorage.php index 8d123e7b873..37f1c12a2e4 100644 --- a/apps/files_sharing/lib/SharedStorage.php +++ b/apps/files_sharing/lib/SharedStorage.php @@ -38,6 +38,7 @@ use OC\Files\Cache\Watcher; use OC\Files\ObjectStore\HomeObjectStoreStorage; use OC\Files\Storage\Common; use OC\Files\Storage\Home; +use OC\User\DisplayNameCache; use OCP\Files\Folder; use OCP\Files\IHomeStorage; use OCP\Files\Node; @@ -51,7 +52,6 @@ use OCP\Files\IRootFolder; use OCP\Files\NotFoundException; use OCP\Files\Storage\IDisableEncryptionStorage; use OCP\Files\Storage\IStorage; -use OCP\IUserManager; use OCP\Lock\ILockingProvider; use OCP\Share\IShare; @@ -416,7 +416,7 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto $this->cache = new \OCA\Files_Sharing\Cache( $storage, $sourceRoot, - \OC::$server->get(IUserManager::class) + \OC::$server->get(DisplayNameCache::class) ); return $this->cache; } |