Skip to content

Commit 83faba5

Browse files
authored
Merge pull request #38591 from nextcloud/fix/caching/avoid-haskey-get
fix(caching): Avoid checking existence before fetching
2 parents e390a35 + b8c61b3 commit 83faba5

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

apps/files_external/lib/Lib/Storage/Swift.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,10 @@ private function normalizePath(string $path) {
126126
* @throws \OCP\Files\StorageNotAvailableException
127127
*/
128128
private function fetchObject(string $path) {
129-
if ($this->objectCache->hasKey($path)) {
129+
$cached = $this->objectCache->get($path);
130+
if ($cached !== null) {
130131
// might be "false" if object did not exist from last check
131-
return $this->objectCache->get($path);
132+
return $cached;
132133
}
133134
try {
134135
$object = $this->getContainer()->getObject($path);

apps/files_sharing/lib/External/Storage.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,9 @@ protected function testRemote(): bool {
265265

266266
private function testRemoteUrl(string $url): bool {
267267
$cache = $this->memcacheFactory->createDistributed('files_sharing_remote_url');
268-
if ($cache->hasKey($url)) {
269-
return (bool)$cache->get($url);
268+
$cached = $cache->get($url);
269+
if ($cached !== null) {
270+
return (bool)$cached;
270271
}
271272

272273
$client = $this->httpClient->newClient();

apps/files_sharing/lib/SharedMount.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,9 @@ private function verifyMountPoint(
117117
$this->eventDispatcher->dispatchTyped($event);
118118
$parent = $event->getParent();
119119

120-
if ($folderExistCache->hasKey($parent)) {
121-
$parentExists = $folderExistCache->get($parent);
120+
$cached = $folderExistCache->get($parent);
121+
if ($cached) {
122+
$parentExists = $cached;
122123
} else {
123124
$parentExists = $this->recipientView->is_dir($parent);
124125
$folderExistCache->set($parent, $parentExists);

lib/private/Accounts/AccountManager.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -795,8 +795,9 @@ private function parseAccountData(IUser $user, $data): Account {
795795
}
796796

797797
public function getAccount(IUser $user): IAccount {
798-
if ($this->internalCache->hasKey($user->getUID())) {
799-
return $this->internalCache->get($user->getUID());
798+
$cached = $this->internalCache->get($user->getUID());
799+
if ($cached !== null) {
800+
return $cached;
800801
}
801802
$account = $this->parseAccountData($user, $this->getUser($user));
802803
$this->internalCache->set($user->getUID(), $account);

0 commit comments

Comments
 (0)