Skip to content

Commit

Permalink
do shallow compare when removing cached mount for user
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Appelman <[email protected]>
  • Loading branch information
icewind1991 committed Apr 26, 2022
1 parent 6a5e2b0 commit 991349a
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions lib/private/Files/Config/UserMountCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/

namespace OC\Files\Config;

use OC\Cache\CappedMemoryCache;
Expand Down Expand Up @@ -56,12 +57,7 @@ class UserMountCache implements IUserMountCache {
*/
private $userManager;

/**
* Cached mount info.
* Map of $userId to ICachedMountInfo.
*
* @var ICache
**/
/** @var CappedMemoryCache<ICachedMountInfo[]> */
private $mountsForUsers;

private LoggerInterface $logger;
Expand Down Expand Up @@ -104,7 +100,9 @@ public function registerMounts(IUser $user, array $mounts, array $mountProviderC

$cachedMounts = $this->getMountsForUser($user);
if (is_array($mountProviderClasses)) {
$cachedMounts = array_filter($cachedMounts, function (ICachedMountInfo $mountInfo) use ($mountProviderClasses) {
$cachedMounts = array_filter($cachedMounts, function (ICachedMountInfo $mountInfo) use (
$mountProviderClasses
) {
return in_array($mountInfo->getMountProvider(), $mountProviderClasses);
});
}
Expand All @@ -113,7 +111,9 @@ public function registerMounts(IUser $user, array $mounts, array $mountProviderC
}, $cachedMounts);
$cachedMounts = array_combine($cachedMountRootIds, $cachedMounts);

/** @var ICachedMountInfo[] $addedMounts */
$addedMounts = [];
/** @var ICachedMountInfo[] $removedMounts */
$removedMounts = [];

foreach ($newMounts as $rootId => $newMount) {
Expand All @@ -136,8 +136,13 @@ public function registerMounts(IUser $user, array $mounts, array $mountProviderC
}
foreach ($removedMounts as $mount) {
$this->removeFromCache($mount);
$index = array_search($mount, $this->mountsForUsers[$user->getUID()]);
unset($this->mountsForUsers[$user->getUID()][$index]);
foreach ($this->mountsForUsers[$user->getUID()] as $index => $mountForUser) {
/** @var ICachedMountInfo $mountForUser */
if ($mount->getRootId() == $mountForUser->getRootId() && $mount->getMountPoint() == $mountForUser->getMountPoint()) {
unset($this->mountsForUsers[$user->getUID()][$index]);
break;
}
}
}
foreach ($changedMounts as $mount) {
$this->updateCachedMount($mount);
Expand Down Expand Up @@ -313,7 +318,7 @@ private function getCacheInfoFromFileId($fileId): array {
$this->cacheInfoCache[$fileId] = [
(int)$row['storage'],
(string)$row['path'],
(int)$row['mimetype']
(int)$row['mimetype'],
];
} else {
throw new NotFoundException('File with id "' . $fileId . '" not found');
Expand Down

0 comments on commit 991349a

Please sign in to comment.