Skip to content

Commit 332b3ef

Browse files
Merge pull request #47754 from nextcloud/fix/noid/cache-appstore-on-dev-instances
fix(appstore): Cache apps.json also on dev instances
2 parents 8cded1e + b2c2c93 commit 332b3ef

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

lib/private/App/AppStore/Fetcher/Fetcher.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
abstract class Fetcher {
2020
public const INVALIDATE_AFTER_SECONDS = 3600;
21+
public const INVALIDATE_AFTER_SECONDS_UNSTABLE = 900;
2122
public const RETRY_AFTER_FAILURE_SECONDS = 300;
2223
public const APP_STORE_URL = 'https://apps.nextcloud.com/api/v1';
2324

@@ -133,12 +134,17 @@ public function get($allowUnstable = false) {
133134
$file = $rootFolder->getFile($this->fileName);
134135
$jsonBlob = json_decode($file->getContent(), true);
135136

136-
// Always get latests apps info if $allowUnstable
137-
if (!$allowUnstable && is_array($jsonBlob)) {
137+
if (is_array($jsonBlob)) {
138138
// No caching when the version has been updated
139139
if (isset($jsonBlob['ncversion']) && $jsonBlob['ncversion'] === $this->getVersion()) {
140140
// If the timestamp is older than 3600 seconds request the files new
141-
if ((int)$jsonBlob['timestamp'] > ($this->timeFactory->getTime() - self::INVALIDATE_AFTER_SECONDS)) {
141+
$invalidateAfterSeconds = self::INVALIDATE_AFTER_SECONDS;
142+
143+
if ($allowUnstable) {
144+
$invalidateAfterSeconds = self::INVALIDATE_AFTER_SECONDS_UNSTABLE;
145+
}
146+
147+
if ((int)$jsonBlob['timestamp'] > ($this->timeFactory->getTime() - $invalidateAfterSeconds)) {
142148
return $jsonBlob['data'];
143149
}
144150

@@ -161,11 +167,6 @@ public function get($allowUnstable = false) {
161167
return [];
162168
}
163169

164-
// Don't store the apps request file
165-
if ($allowUnstable) {
166-
return $responseJson['data'];
167-
}
168-
169170
$file->putContent(json_encode($responseJson));
170171
return json_decode($file->getContent(), true)['data'];
171172
} catch (ConnectException $e) {

0 commit comments

Comments
 (0)