Skip to content

Commit

Permalink
fix(OCMDiscoveryService): Also cache error results during discovery
Browse files Browse the repository at this point in the history
Signed-off-by: provokateurin <[email protected]>
  • Loading branch information
provokateurin authored and backportbot[bot] committed Nov 25, 2024
1 parent 28d70d1 commit 8e9e893
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/private/OCM/OCMDiscoveryService.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ public function discover(string $remote, bool $skipCache = false): IOCMProvider

if (!$skipCache) {
try {
$this->provider->import(json_decode($this->cache->get($remote) ?? '', true, 8, JSON_THROW_ON_ERROR) ?? []);
$cached = $this->cache->get($remote);
if ($cached === false) {
throw new OCMProviderException('Previous discovery failed.');
}

$this->provider->import(json_decode($cached ?? '', true, 8, JSON_THROW_ON_ERROR) ?? []);
if ($this->supportedAPIVersion($this->provider->getApiVersion())) {
return $this->provider; // if cache looks valid, we use it
}
Expand All @@ -82,8 +87,10 @@ public function discover(string $remote, bool $skipCache = false): IOCMProvider
$this->cache->set($remote, $body, 60 * 60 * 24);
}
} catch (JsonException|OCMProviderException $e) {
$this->cache->set($remote, false, 5 * 60);
throw new OCMProviderException('data returned by remote seems invalid - ' . ($body ?? ''));
} catch (\Exception $e) {
$this->cache->set($remote, false, 5 * 60);
$this->logger->warning('error while discovering ocm provider', [
'exception' => $e,
'remote' => $remote
Expand All @@ -92,6 +99,7 @@ public function discover(string $remote, bool $skipCache = false): IOCMProvider
}

if (!$this->supportedAPIVersion($this->provider->getApiVersion())) {
$this->cache->set($remote, false, 5 * 60);
throw new OCMProviderException('API version not supported');
}

Expand Down

0 comments on commit 8e9e893

Please sign in to comment.