diff options
author | John Molakvoæ <skjnldsv@users.noreply.github.com> | 2022-05-13 09:27:28 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-13 09:27:28 +0300 |
commit | fe33e9c08cbbc80738660d2d78838f04d24e0e2e (patch) | |
tree | feab7d407620addc9a7eb50f8bd5789e08434074 /apps | |
parent | 48bb547e8a24dab04bcc18df9bf5f50aa6b7462a (diff) | |
parent | ec6b83cc1891214c7fa3a236626807b4335f9a2f (diff) |
Merge pull request #32250 from nextcloud/cleanup/cappedmemorycache
Diffstat (limited to 'apps')
-rw-r--r-- | apps/files_external/lib/Lib/Storage/AmazonS3.php | 28 | ||||
-rw-r--r-- | apps/files_external/lib/Lib/Storage/SMB.php | 8 | ||||
-rw-r--r-- | apps/files_sharing/lib/MountProvider.php | 1 | ||||
-rw-r--r-- | apps/files_sharing/lib/SharedMount.php | 1 | ||||
-rw-r--r-- | apps/user_ldap/lib/Group_LDAP.php | 12 | ||||
-rw-r--r-- | apps/user_ldap/lib/Helper.php | 13 | ||||
-rw-r--r-- | apps/user_ldap/lib/User/Manager.php | 51 | ||||
-rw-r--r-- | apps/workflowengine/lib/Manager.php | 9 |
8 files changed, 46 insertions, 77 deletions
diff --git a/apps/files_external/lib/Lib/Storage/AmazonS3.php b/apps/files_external/lib/Lib/Storage/AmazonS3.php index d3e9605e5a1..e7a8c5f9329 100644 --- a/apps/files_external/lib/Lib/Storage/AmazonS3.php +++ b/apps/files_external/lib/Lib/Storage/AmazonS3.php @@ -54,6 +54,7 @@ use OCP\Files\IMimeTypeDetector; use OCP\ICacheFactory; use OCP\IMemcache; use OCP\Server; +use OCP\ICache; class AmazonS3 extends \OC\Files\Storage\Common { use S3ConnectionTrait; @@ -63,23 +64,18 @@ class AmazonS3 extends \OC\Files\Storage\Common { return false; } - /** @var CappedMemoryCache|Result[] */ - private $objectCache; + /** @var CappedMemoryCache<array|false> */ + private CappedMemoryCache $objectCache; - /** @var CappedMemoryCache|bool[] */ - private $directoryCache; + /** @var CappedMemoryCache<bool> */ + private CappedMemoryCache $directoryCache; - /** @var CappedMemoryCache|array */ - private $filesCache; + /** @var CappedMemoryCache<array> */ + private CappedMemoryCache $filesCache; - /** @var IMimeTypeDetector */ - private $mimeDetector; - - /** @var bool|null */ - private $versioningEnabled = null; - - /** @var IMemcache */ - private $memCache; + private IMimeTypeDetector $mimeDetector; + private ?bool $versioningEnabled = null; + private ICache $memCache; public function __construct($parameters) { parent::__construct($parameters); @@ -146,10 +142,9 @@ class AmazonS3 extends \OC\Files\Storage\Common { } /** - * @param $key * @return array|false */ - private function headObject($key) { + private function headObject(string $key) { if (!isset($this->objectCache[$key])) { try { $this->objectCache[$key] = $this->getConnection()->headObject([ @@ -165,6 +160,7 @@ class AmazonS3 extends \OC\Files\Storage\Common { } if (is_array($this->objectCache[$key]) && !isset($this->objectCache[$key]["Key"])) { + /** @psalm-suppress InvalidArgument Psalm doesn't understand nested arrays well */ $this->objectCache[$key]["Key"] = $key; } return $this->objectCache[$key]; diff --git a/apps/files_external/lib/Lib/Storage/SMB.php b/apps/files_external/lib/Lib/Storage/SMB.php index c2555f87b93..bdb9b4f9c8f 100644 --- a/apps/files_external/lib/Lib/Storage/SMB.php +++ b/apps/files_external/lib/Lib/Storage/SMB.php @@ -84,10 +84,8 @@ class SMB extends Common implements INotifyStorage { */ protected $root; - /** - * @var IFileInfo[] - */ - protected $statCache; + /** @var CappedMemoryCache<IFileInfo> */ + protected CappedMemoryCache $statCache; /** @var ILogger */ protected $logger; @@ -527,7 +525,7 @@ class SMB extends Common implements INotifyStorage { } try { - $this->statCache = []; + $this->statCache = new CappedMemoryCache(); $content = $this->share->dir($this->buildPath($path)); foreach ($content as $file) { if ($file->isDirectory()) { diff --git a/apps/files_sharing/lib/MountProvider.php b/apps/files_sharing/lib/MountProvider.php index bfb40387622..d27f9e5e0da 100644 --- a/apps/files_sharing/lib/MountProvider.php +++ b/apps/files_sharing/lib/MountProvider.php @@ -109,6 +109,7 @@ class MountProvider implements IMountProvider { $view = new View('/' . $user->getUID() . '/files'); $ownerViews = []; $sharingDisabledForUser = $this->shareManager->sharingDisabledForUser($user->getUID()); + /** @var CappedMemoryCache<bool> $folderExistCache */ $foldersExistCache = new CappedMemoryCache(); foreach ($superShares as $share) { try { diff --git a/apps/files_sharing/lib/SharedMount.php b/apps/files_sharing/lib/SharedMount.php index 398da5eaf23..95ff66c4b71 100644 --- a/apps/files_sharing/lib/SharedMount.php +++ b/apps/files_sharing/lib/SharedMount.php @@ -96,6 +96,7 @@ class SharedMount extends MountPoint implements MoveableMount { * * @param \OCP\Share\IShare $share * @param SharedMount[] $mountpoints + * @param CappedMemoryCache<bool> $folderExistCache * @return string */ private function verifyMountPoint( diff --git a/apps/user_ldap/lib/Group_LDAP.php b/apps/user_ldap/lib/Group_LDAP.php index f9d9b061743..8fcb10cb850 100644 --- a/apps/user_ldap/lib/Group_LDAP.php +++ b/apps/user_ldap/lib/Group_LDAP.php @@ -55,12 +55,12 @@ use Psr\Log\LoggerInterface; class Group_LDAP extends BackendUtility implements GroupInterface, IGroupLDAP, IGetDisplayNameBackend, IDeleteGroupBackend { protected $enabled = false; - /** @var string[][] $cachedGroupMembers array of users with gid as key */ - protected $cachedGroupMembers; - /** @var string[] $cachedGroupsByMember array of groups with uid as key */ - protected $cachedGroupsByMember; - /** @var string[] $cachedNestedGroups array of groups with gid (DN) as key */ - protected $cachedNestedGroups; + /** @var CappedMemoryCache<string[]> $cachedGroupMembers array of users with gid as key */ + protected CappedMemoryCache $cachedGroupMembers; + /** @var CappedMemoryCache<string[]> $cachedGroupsByMember array of groups with uid as key */ + protected CappedMemoryCache $cachedGroupsByMember; + /** @var CappedMemoryCache<string[]> $cachedNestedGroups array of groups with gid (DN) as key */ + protected CappedMemoryCache $cachedNestedGroups; /** @var GroupPluginManager */ protected $groupPluginManager; /** @var LoggerInterface */ diff --git a/apps/user_ldap/lib/Helper.php b/apps/user_ldap/lib/Helper.php index 437fab6b6a8..3ca5de67874 100644 --- a/apps/user_ldap/lib/Helper.php +++ b/apps/user_ldap/lib/Helper.php @@ -35,15 +35,10 @@ use OCP\IConfig; use OCP\IDBConnection; class Helper { - - /** @var IConfig */ - private $config; - - /** @var IDBConnection */ - private $connection; - - /** @var CappedMemoryCache */ - protected $sanitizeDnCache; + private IConfig $config; + private IDBConnection $connection; + /** @var CappedMemoryCache<string> */ + protected CappedMemoryCache $sanitizeDnCache; public function __construct(IConfig $config, IDBConnection $connection) { diff --git a/apps/user_ldap/lib/User/Manager.php b/apps/user_ldap/lib/User/Manager.php index e752b113e3f..e52b093f5af 100644 --- a/apps/user_ldap/lib/User/Manager.php +++ b/apps/user_ldap/lib/User/Manager.php @@ -47,43 +47,20 @@ use Psr\Log\LoggerInterface; * cache */ class Manager { - /** @var Access */ - protected $access; - - /** @var IConfig */ - protected $ocConfig; - - /** @var IDBConnection */ - protected $db; - - /** @var IUserManager */ - protected $userManager; - - /** @var INotificationManager */ - protected $notificationManager; - - /** @var FilesystemHelper */ - protected $ocFilesystem; - - /** @var LoggerInterface */ - protected $logger; - - /** @var Image */ - protected $image; - - /** @param \OCP\IAvatarManager */ - protected $avatarManager; - - /** - * @var CappedMemoryCache $usersByDN - */ - protected $usersByDN; - /** - * @var CappedMemoryCache $usersByUid - */ - protected $usersByUid; - /** @var IManager */ - private $shareManager; + protected ?Access $access = null; + protected IConfig $ocConfig; + protected IDBConnection $db; + protected IUserManager $userManager; + protected INotificationManager $notificationManager; + protected FilesystemHelper $ocFilesystem; + protected LoggerInterface $logger; + protected Image $image; + protected IAvatarManager $avatarManager; + /** @var CappedMemoryCache<User> $usersByDN */ + protected CappedMemoryCache $usersByDN; + /** @var CappedMemoryCache<User> $usersByUid */ + protected CappedMemoryCache $usersByUid; + private IManager $shareManager; public function __construct( IConfig $ocConfig, diff --git a/apps/workflowengine/lib/Manager.php b/apps/workflowengine/lib/Manager.php index 34dbf507b91..f6c3e3086c2 100644 --- a/apps/workflowengine/lib/Manager.php +++ b/apps/workflowengine/lib/Manager.php @@ -109,8 +109,8 @@ class Manager implements IManager { /** @var ILogger */ protected $logger; - /** @var CappedMemoryCache */ - protected $operationsByScope = []; + /** @var CappedMemoryCache<int[]> */ + protected CappedMemoryCache $operationsByScope; /** @var IUserSession */ protected $session; @@ -350,10 +350,11 @@ class Manager implements IManager { $qb->setParameters(['scope' => $scopeContext->getScope(), 'scopeId' => $scopeContext->getScopeId()]); $result = $qb->execute(); - $this->operationsByScope[$scopeContext->getHash()] = []; + $operations = []; while (($opId = $result->fetchOne()) !== false) { - $this->operationsByScope[$scopeContext->getHash()][] = (int)$opId; + $operations[] = (int)$opId; } + $this->operationsByScope[$scopeContext->getHash()] = $operations; $result->closeCursor(); return in_array($id, $this->operationsByScope[$scopeContext->getHash()], true); |