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

[stable29] fix(appstore): Cache apps.json also on dev instances #47765

Merged
merged 1 commit into from
Sep 5, 2024
Merged
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
17 changes: 9 additions & 8 deletions lib/private/App/AppStore/Fetcher/Fetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@

abstract class Fetcher {
public const INVALIDATE_AFTER_SECONDS = 3600;
public const INVALIDATE_AFTER_SECONDS_UNSTABLE = 900;
public const RETRY_AFTER_FAILURE_SECONDS = 300;
public const APP_STORE_URL = 'https://apps.nextcloud.com/api/v1';

Expand Down Expand Up @@ -157,12 +158,17 @@ public function get($allowUnstable = false) {
$file = $rootFolder->getFile($this->fileName);
$jsonBlob = json_decode($file->getContent(), true);

// Always get latests apps info if $allowUnstable
if (!$allowUnstable && is_array($jsonBlob)) {
if (is_array($jsonBlob)) {
// No caching when the version has been updated
if (isset($jsonBlob['ncversion']) && $jsonBlob['ncversion'] === $this->getVersion()) {
// If the timestamp is older than 3600 seconds request the files new
if ((int)$jsonBlob['timestamp'] > ($this->timeFactory->getTime() - self::INVALIDATE_AFTER_SECONDS)) {
$invalidateAfterSeconds = self::INVALIDATE_AFTER_SECONDS;

if ($allowUnstable) {
$invalidateAfterSeconds = self::INVALIDATE_AFTER_SECONDS_UNSTABLE;
}

if ((int)$jsonBlob['timestamp'] > ($this->timeFactory->getTime() - $invalidateAfterSeconds)) {
return $jsonBlob['data'];
}

Expand All @@ -185,11 +191,6 @@ public function get($allowUnstable = false) {
return [];
}

// Don't store the apps request file
if ($allowUnstable) {
return $responseJson['data'];
}

$file->putContent(json_encode($responseJson));
return json_decode($file->getContent(), true)['data'];
} catch (ConnectException $e) {
Expand Down
Loading