From 7c9aad5c4c670511f4adab78c39b016b7f054b53 Mon Sep 17 00:00:00 2001 From: Beatrycze Volk <beatrycze.volk@slub-dresden.de> Date: Fri, 20 Oct 2023 10:32:26 +0200 Subject: [PATCH] Remove cache for result list --- Classes/Controller/RecommenderController.php | 145 +++++-------------- ext_localconf.php | 11 +- 2 files changed, 35 insertions(+), 121 deletions(-) diff --git a/Classes/Controller/RecommenderController.php b/Classes/Controller/RecommenderController.php index c207d82..98c3100 100644 --- a/Classes/Controller/RecommenderController.php +++ b/Classes/Controller/RecommenderController.php @@ -16,9 +16,6 @@ namespace Slub\Bison\Controller; use Slub\Bison\Model\Journal; use Slub\Bison\Model\Language; use Slub\Bison\Model\Subject; -use TYPO3\CMS\Core\Cache\CacheManager; -use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface; -use TYPO3\CMS\Core\Utility\GeneralUtility; /** * The recommender controller for the Bison extension @@ -27,7 +24,6 @@ use TYPO3\CMS\Core\Utility\GeneralUtility; * @package TYPO3 * @subpackage bison * @access public - * @property FrontendInterface $cache This holds the cache * @property string $title This hold the last searched title * @property string $abstract This hold the last searched abstract * @property string $references This hold the last searched references @@ -36,38 +32,6 @@ use TYPO3\CMS\Core\Utility\GeneralUtility; class RecommenderController extends AbstractController { - /** - * This holds the cache - * - * @var FrontendInterface - * @access private - */ - private $cache; - - /** - * This hold the last searched title - * - * @var string - * @access private - */ - private $title = ''; - - /** - * This hold the last searched abstract - * - * @var string - * @access private - */ - private $abstract = ''; - - /** - * This hold the last searched references - * - * @var string - * @access private - */ - private $references = ''; - /** * The recommender function returning journals based on title etc. * @@ -75,58 +39,43 @@ class RecommenderController extends AbstractController */ public function mainAction() { - $this->cache = GeneralUtility::makeInstance(CacheManager::class)->getCache('tx_bison_result'); - $resultList = $this->cache->get('result_list'); - $this->results = []; - // execute query if there is no cached result list, at least one request - // parameter is not empty and differs from previously stored parameters - if (!$resultList && $this->existRequestParameters() && $this->areCurrentRequestParametersDifferent()) { - //store request parameters to be able use them later in checks - $this->title = !empty($this->requestData['title']) ? $this->requestData['title'] : ''; - $this->abstract = !empty($this->requestData['abstract']) ? $this->requestData['abstract'] : ''; - $this->references = !empty($this->requestData['references']) ? $this->requestData['references'] : ''; - - try { - $response = $this->client->request( - 'POST', - 'search', - [ - 'json' => [ - 'title' => $this->requestData['title'], - 'abstract' => $this->requestData['abstract'], - 'references' => $this->requestData['references'], - ] + //store request parameters to be able use them later in checks + $this->title = !empty($this->requestData['title']) ? $this->requestData['title'] : ''; + $this->abstract = !empty($this->requestData['abstract']) ? $this->requestData['abstract'] : ''; + $this->references = !empty($this->requestData['references']) ? $this->requestData['references'] : ''; + + try { + $response = $this->client->request( + 'POST', + 'search', + [ + 'json' => [ + 'title' => $this->requestData['title'], + 'abstract' => $this->requestData['abstract'], + 'references' => $this->requestData['references'], ] - ); - - if ($response->getStatusCode() === 200) { - $content = $response->getBody()->getContents(); - $result = json_decode($content); - foreach ($result->journals as $journal) { - $this->results[] = new Journal($journal); - } - - $this->processResults(); + ] + ); + + if ($response->getStatusCode() === 200) { + $content = $response->getBody()->getContents(); + $result = json_decode($content); + foreach ($result->journals as $journal) { + $this->results[] = new Journal($journal); + } - $this->cache->set('result_list', $this->results); - $this->cache->set('result_language', $result->language); - $this->cache->set('result_subject', $result->subject); + $this->processResults(); - $this->assignViewVariables(); - } else { - $this->logger->error('Server response error: '.$response->getStatusCode()); - $this->view->assign('error','Server response error: '.$response->getStatusCode()); - } - } catch (\Exception $e) { - $this->logger->error('Request error: '.$e->getMessage()); - $this->view->assign('error', $e->getMessage()); + $this->assignViewVariables($result); + } else { + $this->logger->error('Server response error: '.$response->getStatusCode()); + $this->view->assign('error','Server response error: '.$response->getStatusCode()); } - } else if (!empty($resultList) && $this->existRequestParameters()) { - $this->results = $resultList; - - $this->assignViewVariables(); + } catch (\Exception $e) { + $this->logger->error('Request error: '.$e->getMessage()); + $this->view->assign('error', $e->getMessage()); } $this->view->assign('contact', $this->getContactPerson()); @@ -140,14 +89,14 @@ class RecommenderController extends AbstractController * * @return void */ - private function assignViewVariables() { + private function assignViewVariables($result) { $this->view->assign('maxApc', $this->getMaxApc()); $this->view->assign('maxPublicationTime', $this->getMaxPublicationTime()); $this->view->assign('keywords', $this->getKeywords()); $this->view->assign('languages', $this->getLanguages()); $this->view->assign('subjects', $this->getSubjects()); - $this->view->assign('suggestLanguage', $this->getSuggestLanguage($this->cache->get('result_language'))); - $this->view->assign('suggestSubject', $this->getSuggestSubject($this->cache->get('result_subject'))); + $this->view->assign('suggestLanguage', $this->getSuggestLanguage($result->language)); + $this->view->assign('suggestSubject', $this->getSuggestSubject($result->subject)); $this->view->assign('displayMismatchedResults', filter_var($this->extConfig['displayMismatchedResults'], FILTER_VALIDATE_BOOLEAN)); $this->view->assign('displayMirrorJournals', filter_var($this->extConfig['displayMirrorJournals'], FILTER_VALIDATE_BOOLEAN)); $this->view->assign('isFilterTooStrict', $this->isFilterTooStrict()); @@ -155,32 +104,6 @@ class RecommenderController extends AbstractController $this->view->assign('results', $this->results); } - /** - * Checks if at least one request parameter differs. - * - * @return bool - */ - private function areCurrentRequestParametersDifferent() { - $title = !empty($this->requestData['title']) ? $this->requestData['title'] : ''; - $abstract = !empty($this->requestData['abstract']) ? $this->requestData['abstract'] : ''; - $references = !empty($this->requestData['references']) ? $this->requestData['references'] : ''; - - return $this->title !== $title - || $this->abstract !== $abstract - || $this->references !== $references; - } - - /** - * Checks if the request parameters exist. - * - * @return bool - */ - private function existRequestParameters() { - return !empty($this->requestData['title']) - || !empty($this->requestData['abstract']) - || !empty($this->requestData['references']); - } - /** * Checks if local filters are too strict. It is a case when after * filtering we have no results, but without filters there are results. diff --git a/ext_localconf.php b/ext_localconf.php index 34f1840..f1375a0 100644 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -12,15 +12,6 @@ defined('TYPO3') || die(); if (!isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['tx_bison_currency']['options']['defaultLifeTime'])) { $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['tx_bison_currency']['options']['defaultLifeTime'] = 87600; // 87600 seconds = 1 day } - if (!is_array($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['tx_bison_result'])) { - $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['tx_bison_result'] = []; - } - if (!isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['tx_bison_result']['backend'])) { - $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['tx_bison_result']['backend'] = 'TYPO3\\CMS\\Core\\Cache\\Backend\\SimpleFileBackend'; - } - if (!isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['tx_bison_result']['options']['defaultLifeTime'])) { - $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['tx_bison_result']['options']['defaultLifeTime'] = 3600; // 3600 seconds = 1 hour - } if (!isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['fluid']['namespaces']['bison'])) { $GLOBALS['TYPO3_CONF_VARS']['SYS']['fluid']['namespaces']['bison'] = [ 'Slub\Bison\ViewHelpers', @@ -35,7 +26,7 @@ defined('TYPO3') || die(); ], // non-cacheable actions [ - \Slub\Bison\Controller\RecommenderController::class => '' + \Slub\Bison\Controller\RecommenderController::class => 'main' ] ); -- GitLab