diff options
author | Vincent Petry <pvince81@owncloud.com> | 2016-06-16 09:27:48 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-06-16 09:27:48 +0200 |
commit | 9c328de4abaa61a19be2ffb9ff80f52cb2dcb6c3 (patch) | |
tree | fa487e118f039d1118f1fcf718f8d340293e894b /lib | |
parent | 1251df3e172ca6f92db9ebaf1e4b74a28f3652f0 (diff) | |
parent | ea4c5e6e0abb978d8cc49e604966609e97bec525 (diff) | |
download | nextcloud-server-9c328de4abaa61a19be2ffb9ff80f52cb2dcb6c3.tar.gz nextcloud-server-9c328de4abaa61a19be2ffb9ff80f52cb2dcb6c3.zip |
Merge pull request #24415 from owncloud/optimize_sharingdisabled_for_user
Optimize isSharingDisabledForUser
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Share20/Manager.php | 36 | ||||
-rw-r--r-- | lib/public/Util.php | 19 |
2 files changed, 39 insertions, 16 deletions
diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index ceaaa58cf6e..e2730f4d5fb 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -24,25 +24,24 @@ namespace OC\Share20; +use OC\Cache\CappedMemoryCache; use OC\Files\Mount\MoveableMount; +use OCP\Files\File; +use OCP\Files\Folder; use OCP\Files\IRootFolder; +use OCP\Files\Mount\IMountManager; use OCP\Files\NotFoundException; -use OCP\IUserManager; -use OCP\Share\IManager; -use OCP\Share\IProviderFactory; -use OC\Share20\Exception\BackendError; use OCP\IConfig; +use OCP\IGroupManager; use OCP\IL10N; use OCP\ILogger; -use OCP\Security\ISecureRandom; +use OCP\IUserManager; use OCP\Security\IHasher; -use OCP\Files\Mount\IMountManager; -use OCP\IGroupManager; -use OCP\Files\File; -use OCP\Files\Folder; - -use OCP\Share\Exceptions\ShareNotFound; +use OCP\Security\ISecureRandom; use OCP\Share\Exceptions\GenericShareException; +use OCP\Share\Exceptions\ShareNotFound; +use OCP\Share\IManager; +use OCP\Share\IProviderFactory; /** * This class is the communication hub for all sharing related operations. @@ -69,6 +68,9 @@ class Manager implements IManager { private $userManager; /** @var IRootFolder */ private $rootFolder; + /** @var CappedMemoryCache */ + private $sharingDisabledForUsersCache; + /** * Manager constructor. @@ -106,6 +108,7 @@ class Manager implements IManager { $this->factory = $factory; $this->userManager = $userManager; $this->rootFolder = $rootFolder; + $this->sharingDisabledForUsersCache = new CappedMemoryCache(); } /** @@ -1209,6 +1212,14 @@ class Manager implements IManager { * @return bool */ public function sharingDisabledForUser($userId) { + if ($userId === null) { + return false; + } + + if (isset($this->sharingDisabledForUsersCache[$userId])) { + return $this->sharingDisabledForUsersCache[$userId]; + } + if ($this->config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes') { $groupsList = $this->config->getAppValue('core', 'shareapi_exclude_groups_list', ''); $excludedGroups = json_decode($groupsList); @@ -1224,10 +1235,13 @@ class Manager implements IManager { // if the user is only in groups which are disabled for sharing then // sharing is also disabled for the user if (empty($remainingGroups)) { + $this->sharingDisabledForUsersCache[$userId] = true; return true; } } } + + $this->sharingDisabledForUsersCache[$userId] = false; return false; } diff --git a/lib/public/Util.php b/lib/public/Util.php index eb573168e10..687f4e78f69 100644 --- a/lib/public/Util.php +++ b/lib/public/Util.php @@ -63,6 +63,9 @@ class Util { const ERROR=3; const FATAL=4; + /** \OCP\Share\IManager */ + private static $shareManager; + /** * get the current installed version of ownCloud * @return array @@ -171,13 +174,19 @@ class Util { * * @return boolean * @since 7.0.0 + * @deprecated 9.1.0 Use \OC::$server->getShareManager()->sharingDisabledForUser */ public static function isSharingDisabledForUser() { - return \OC_Util::isSharingDisabledForUser( - \OC::$server->getConfig(), - \OC::$server->getGroupManager(), - \OC::$server->getUserSession()->getUser() - ); + if (self::$shareManager === null) { + self::$shareManager = \OC::$server->getShareManager(); + } + + $user = \OC::$server->getUserSession()->getUser(); + if ($user !== null) { + $user = $user->getUID(); + } + + return self::$shareManager->sharingDisabledForUser($user); } /** |