Upload via GUI (335 Dateien)
This commit is contained in:
@@ -45,24 +45,30 @@ function theme_catalog_fetch(): array
|
||||
}
|
||||
|
||||
/**
|
||||
* Theme-Katalog mit Zwischenspeicher (1 Stunde), damit er ohne Klick sofort angezeigt wird. $refresh erzwingt einen neuen Abruf.
|
||||
* Theme-Katalog mit kurzem Zwischenspeicher (Standard 5 Minuten), damit er ohne Klick sofort angezeigt wird. $refresh erzwingt einen neuen
|
||||
* Abruf. Ist der Katalog-Server nicht erreichbar, bleibt der letzte Stand sichtbar und es wird zwei Minuten lang nicht erneut gefragt.
|
||||
*
|
||||
* @return array{ok:bool, error?:string, themes?:array, cached_at?:int}
|
||||
* @return array{ok:bool, error?:string, themes?:array, cached_at?:int, stale?:bool}
|
||||
*/
|
||||
function theme_catalog_cached(bool $refresh = false): array
|
||||
function theme_catalog_cached(bool $refresh = false, int $maxAge = 300): array
|
||||
{
|
||||
$key = hash('sha256', theme_catalog_url());
|
||||
if (!$refresh) {
|
||||
$cached = json_decode((string) get_setting('theme_catalog_cache', ''), true);
|
||||
if (is_array($cached) && ($cached['key'] ?? '') === $key && time() - (int) ($cached['at'] ?? 0) < 3600) {
|
||||
return ['ok' => true, 'themes' => $cached['themes'], 'cached_at' => (int) $cached['at']];
|
||||
}
|
||||
$cached = json_decode((string) get_setting('theme_catalog_cache', ''), true);
|
||||
$usable = is_array($cached) && ($cached['key'] ?? '') === $key;
|
||||
if (!$refresh && $usable) {
|
||||
$age = time() - (int) ($cached['at'] ?? 0);
|
||||
if ($age < $maxAge) return ['ok' => true, 'themes' => $cached['themes'], 'cached_at' => (int) $cached['at']];
|
||||
if (time() - (int) get_setting('theme_catalog_fail_at', '0') < 120) return ['ok' => true, 'themes' => $cached['themes'], 'cached_at' => (int) $cached['at'], 'stale' => true];
|
||||
}
|
||||
$res = theme_catalog_fetch();
|
||||
if ($res['ok']) {
|
||||
set_setting('theme_catalog_cache', json_encode(['key' => $key, 'at' => time(), 'themes' => $res['themes']], JSON_UNESCAPED_UNICODE));
|
||||
set_setting('theme_catalog_fail_at', '0');
|
||||
$res['cached_at'] = time();
|
||||
return $res;
|
||||
}
|
||||
set_setting('theme_catalog_fail_at', (string) time());
|
||||
if (!$refresh && $usable) return ['ok' => true, 'themes' => $cached['themes'], 'cached_at' => (int) $cached['at'], 'stale' => true];
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user