Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(caching): Avoid checking existence before fetching #38591

Merged
merged 1 commit into from
Jun 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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