Skip to content

Commit

Permalink
Merge pull request #38591 from nextcloud/fix/caching/avoid-haskey-get
Browse files Browse the repository at this point in the history
fix(caching): Avoid checking existence before fetching
  • Loading branch information
szaimen committed Jun 12, 2023
2 parents e390a35 + b8c61b3 commit 83faba5
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
5 changes: 3 additions & 2 deletions apps/files_external/lib/Lib/Storage/Swift.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,10 @@ private function normalizePath(string $path) {
* @throws \OCP\Files\StorageNotAvailableException
*/
private function fetchObject(string $path) {
if ($this->objectCache->hasKey($path)) {
$cached = $this->objectCache->get($path);
if ($cached !== null) {
// might be "false" if object did not exist from last check
return $this->objectCache->get($path);
return $cached;
}
try {
$object = $this->getContainer()->getObject($path);
Expand Down
5 changes: 3 additions & 2 deletions apps/files_sharing/lib/External/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,9 @@ protected function testRemote(): bool {

private function testRemoteUrl(string $url): bool {
$cache = $this->memcacheFactory->createDistributed('files_sharing_remote_url');
if ($cache->hasKey($url)) {
return (bool)$cache->get($url);
$cached = $cache->get($url);
if ($cached !== null) {
return (bool)$cached;
}

$client = $this->httpClient->newClient();
Expand Down
5 changes: 3 additions & 2 deletions apps/files_sharing/lib/SharedMount.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,9 @@ private function verifyMountPoint(
$this->eventDispatcher->dispatchTyped($event);
$parent = $event->getParent();

if ($folderExistCache->hasKey($parent)) {
$parentExists = $folderExistCache->get($parent);
$cached = $folderExistCache->get($parent);
if ($cached) {
$parentExists = $cached;
} else {
$parentExists = $this->recipientView->is_dir($parent);
$folderExistCache->set($parent, $parentExists);
Expand Down
5 changes: 3 additions & 2 deletions lib/private/Accounts/AccountManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -795,8 +795,9 @@ private function parseAccountData(IUser $user, $data): Account {
}

public function getAccount(IUser $user): IAccount {
if ($this->internalCache->hasKey($user->getUID())) {
return $this->internalCache->get($user->getUID());
$cached = $this->internalCache->get($user->getUID());
if ($cached !== null) {
return $cached;
}
$account = $this->parseAccountData($user, $this->getUser($user));
$this->internalCache->set($user->getUID(), $account);
Expand Down

0 comments on commit 83faba5

Please sign in to comment.