From 746094e657f1e4a882503c453c6ee5b652b5b84a Mon Sep 17 00:00:00 2001 From: provokateurin Date: Fri, 15 Nov 2024 14:25:51 +0100 Subject: [PATCH] fix(OCMDiscoveryService): Also cache error results during discovery Signed-off-by: provokateurin --- lib/private/OCM/OCMDiscoveryService.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/private/OCM/OCMDiscoveryService.php b/lib/private/OCM/OCMDiscoveryService.php index 279162c76f283..6d4286589e4c1 100644 --- a/lib/private/OCM/OCMDiscoveryService.php +++ b/lib/private/OCM/OCMDiscoveryService.php @@ -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 } @@ -85,8 +90,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, 60 * 60); throw new OCMProviderException('data returned by remote seems invalid - ' . ($body ?? '')); } catch (\Exception $e) { + $this->cache->set($remote, false, 60 * 60); $this->logger->warning('error while discovering ocm provider', [ 'exception' => $e, 'remote' => $remote @@ -95,6 +102,7 @@ public function discover(string $remote, bool $skipCache = false): IOCMProvider } if (!$this->supportedAPIVersion($this->provider->getApiVersion())) { + $this->cache->set($remote, false, 60 * 60); throw new OCMProviderException('API version not supported'); }