Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
SLUB Bison
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TYPO3
Extensions
SLUB Bison
Commits
6cd2b40f
Commit
6cd2b40f
authored
1 year ago
by
Beatrycze Volk
Browse files
Options
Downloads
Patches
Plain Diff
Use caching mechanism for storing result list
parent
3e5845ad
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
Classes/Controller/RecommenderController.php
+117
-23
117 additions, 23 deletions
Classes/Controller/RecommenderController.php
Classes/Utility/CurrencyConverter.php
+4
-3
4 additions, 3 deletions
Classes/Utility/CurrencyConverter.php
ext_localconf.php
+9
-0
9 additions, 0 deletions
ext_localconf.php
with
130 additions
and
26 deletions
Classes/Controller/RecommenderController.php
+
117
−
23
View file @
6cd2b40f
...
...
@@ -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
);
}
}
This diff is collapsed.
Click to expand it.
Classes/Utility/CurrencyConverter.php
+
4
−
3
View file @
6cd2b40f
...
...
@@ -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 Log
Mana
ger $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
;
...
...
This diff is collapsed.
Click to expand it.
ext_localconf.php
+
9
−
0
View file @
6cd2b40f
...
...
@@ -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'
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment