Skip to content
Snippets Groups Projects
Commit 6cd2b40f authored by Beatrycze Volk's avatar Beatrycze Volk
Browse files

Use caching mechanism for storing result list

parent 3e5845ad
No related branches found
No related tags found
No related merge requests found
......@@ -13,10 +13,12 @@ namespace Slub\Bison\Controller;
* (c) 2022 Beatrycze Volk <beatrycze.volk@slub-dresden.de>, SLUB
*/
use Slub\Bison\Domain\Repository\JournalRepository;
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
......@@ -25,17 +27,46 @@ use Slub\Bison\Model\Subject;
* @package TYPO3
* @subpackage bison
* @access public
* @property JournalRepository $journalRepository
* @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
* @property array<Journal> $results This holds the journals for displaying to the frontend
*/
class RecommenderController extends AbstractController
{
/**
* @var array<Journal>
* 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 $results;
private $abstract = '';
/**
* This hold the last searched references
*
* @var string
* @access private
*/
private $references = '';
/**
* The recommender function returning journals based on title etc.
......@@ -44,9 +75,19 @@ 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 = [];
if (!empty($this->requestData['title']) || !empty($this->requestData['abstract']) || !empty($this->requestData['references'])) {
// 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',
......@@ -67,35 +108,76 @@ class RecommenderController extends AbstractController
$this->results[] = new Journal($journal);
}
$this->indexDatabaseList->assignIndexDatabases($this->results);
$this->localPriceList->assignLocalPrices($this->results);
$this->mirrorJournalList->assignMirrorJournals($this->results);
$this->mirrorJournalList->markMirrorJournals($this->results);
$this->localFilter->filter($this->results);
$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($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());
$this->view->assign('countResults', $this->countResultsAfterFilter());
$this->view->assign('results', $this->results);
$this->processResults();
$this->cache->set('result_list', $this->results);
$this->cache->set('result_language', $result->language);
$this->cache->set('result_subject', $result->subject);
$this->assignViewVariables();
}
} catch (\Exception $e) {
$this->logger->error('Request error: '.$e->getMessage());
$this->view->assign('error', $e->getMessage());
}
} else if (!empty($resultList)) {
$this->results = $resultList;
$this->assignViewVariables();
}
$this->view->assign('contact', $this->getContactPerson());
$this->view->assign('viewData', $this->viewData);
}
/**
* Assign view variables.
*
* @param mixed $result
*
* @return void
*/
private function assignViewVariables() {
$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('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());
$this->view->assign('countResults', $this->countResultsAfterFilter());
$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.
......@@ -265,4 +347,16 @@ class RecommenderController extends AbstractController
});
return array_values($subjects);
}
/** Apply local information and filters.
*
* @return void
*/
private function processResults() {
$this->indexDatabaseList->assignIndexDatabases($this->results);
$this->localPriceList->assignLocalPrices($this->results);
$this->mirrorJournalList->assignMirrorJournals($this->results);
$this->mirrorJournalList->markMirrorJournals($this->results);
$this->localFilter->filter($this->results);
}
}
......@@ -12,6 +12,7 @@ namespace SLUB\Bison\Utility;
*/
use TYPO3\CMS\Core\Cache\CacheManager;
use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
use TYPO3\CMS\Core\Http\RequestFactory;
use TYPO3\CMS\Core\Log\Logger;
use TYPO3\CMS\Core\Log\LogManager;
......@@ -24,8 +25,8 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
* @package TYPO3
* @subpackage bison
* @access public
* @property CacheManager $cache This holds the cache
* @property LogManager $logger This holds the logger
* @property FrontendInterface $cache This holds the cache
* @property Logger $logger This holds the logger
* @property RequestFactory $logger This holds the request factory
*/
class CurrencyConverter implements \TYPO3\CMS\Core\SingletonInterface
......@@ -35,7 +36,7 @@ class CurrencyConverter implements \TYPO3\CMS\Core\SingletonInterface
/**
* This holds the cache
*
* @var CacheManager
* @var FrontendInterface
* @access private
*/
private $cache;
......
......@@ -12,6 +12,15 @@ 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',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment