From d4fb2ba46a4dd3f45e7bb4f102f7b3ee744fecc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Mon, 9 Sep 2024 00:24:02 +0200 Subject: [PATCH] Try to retrieve the part from the API in getDetails, if the DTO was not cached before --- .../Providers/OEMSecretsProvider.php | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/Services/InfoProviderSystem/Providers/OEMSecretsProvider.php b/src/Services/InfoProviderSystem/Providers/OEMSecretsProvider.php index 84eb3e38..0a743d49 100644 --- a/src/Services/InfoProviderSystem/Providers/OEMSecretsProvider.php +++ b/src/Services/InfoProviderSystem/Providers/OEMSecretsProvider.php @@ -420,16 +420,24 @@ class OEMSecretsProvider implements InfoProviderInterface $cacheItem = $this->partInfoCache->getItem($cacheKey); if ($cacheItem->isHit()) { - $details = $cacheItem->get(); - } else { - // If the details are not found in the cache, throw an exception - throw new \RuntimeException("Details not found for provider_id $id"); + return $cacheItem->get(); + } + //If we have no cached result yet, we extract the part number (first part of our ID) and search for it + $partNumber = explode('|', $id)[0]; + + //The searchByKeyword method will write the results to cache, so we can just try it again afterwards + $this->searchByKeyword($partNumber); + + $cacheItem = $this->partInfoCache->getItem($cacheKey); + if ($cacheItem->isHit()) { + return $cacheItem->get(); } - return $details; + // If the details still are not found in the cache, throw an exception + throw new \RuntimeException("Details not found for provider_id $id"); } - + /** * A list of capabilities this provider supports (which kind of data it can provide). * Not every part have to contain all of these data, but the provider should be able to provide them in general.