Skip to content

Commit f7aea0e

Browse files
Merge pull request #8 from michaelkubina/pagegrid_optimization
[OPTIMIZATION] Add pagegrid caching
2 parents ddf7e74 + 93eb255 commit f7aea0e

3 files changed

Lines changed: 33 additions & 11 deletions

File tree

Classes/Controller/AbstractController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ private function getDocumentByUid(int $documentId)
516516
$this->document = $this->documentRepository->findOneByIdAndSettings($documentId);
517517

518518
if ($this->document) {
519-
$doc = AbstractDocument::getInstance($this->document->getLocation(), $this->settings, true);
519+
$doc = AbstractDocument::getInstance($this->document->getLocation(), $this->settings, false);
520520
} else {
521521
$this->logger->error('Invalid UID "' . $documentId . '" or PID "' . $this->settings['storagePid'] . '" for document loading');
522522
}

Classes/Controller/PageGridController.php

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Kitodo\Dlf\Pagination\PageGridPagination;
1515
use Kitodo\Dlf\Pagination\PageGridPaginator;
16+
use TYPO3\CMS\Core\Cache\CacheManager;
1617
use TYPO3\CMS\Core\Utility\GeneralUtility;
1718

1819
/**
@@ -43,19 +44,31 @@ public function mainAction(): void
4344
return;
4445
}
4546

46-
$entryArray = [];
47-
48-
$numPages = $this->document->getCurrentDocument()->numPages;
49-
// Iterate through visible page set and display thumbnails.
50-
for ($i = 1; $i <= $numPages; $i++) {
51-
$foundEntry = $this->getEntry($i, $this->extConf['files']['fileGrpThumbs']);
52-
$foundEntry['state'] = ($i == $this->requestData['page']) ? 'cur' : 'no';
53-
$entryArray[] = $foundEntry;
54-
}
55-
5647
// Get current page from request data because the parameter is shared between plugins
5748
$currentPage = $this->requestData['page'] ?? 1;
5849

50+
// access cachemanager for pagegrid
51+
$cacheManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Cache\CacheManager::class);
52+
$cache = $cacheManager->getCache('tx_dlf_pagegrid');
53+
$cacheKey = $this->document->getCurrentDocument()->recordId;
54+
$cachedData = $cache->get($cacheKey);
55+
56+
if ($cachedData) {
57+
$entryArray = $cachedData; //load from cache
58+
} else {
59+
$numPages = $this->document->getCurrentDocument()->numPages;
60+
61+
for ($i = 1; $i <= $numPages; $i++) {
62+
$foundEntry = $this->getEntry($i, $this->extConf['files']['fileGrpThumbs']);
63+
$foundEntry['state'] = 'no';
64+
$entryArray[] = $foundEntry;
65+
}
66+
67+
$cache->set($cacheKey, $entryArray, [], 86400);
68+
}
69+
// mark currently active page
70+
$entryArray[$currentPage - 1]['state'] = 'cur';
71+
5972
$itemsPerPage = $this->settings['paginate']['itemsPerPage'];
6073
if (empty($itemsPerPage)) {
6174
$itemsPerPage = 25;

ext_localconf.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,15 @@
9999
if (!isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['tx_dlf_doc']['options']['defaultLifeTime'])) {
100100
$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['tx_dlf_doc']['options']['defaultLifeTime'] = 86400; // 86400 seconds = 1 day
101101
}
102+
// Use Caching Framework for PageGrid $entryArray caching
103+
$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['tx_dlf_pagegrid'] ??= [];
104+
105+
if (!isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['tx_dlf_pagegrid']['backend'])) {
106+
$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['tx_dlf_pagegrid']['backend'] = 'TYPO3\\CMS\\Core\\Cache\\Backend\\FileBackend';
107+
}
108+
$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['tx_dlf_pagegrid']['frontend'] = 'TYPO3\\CMS\\Core\\Cache\\Frontend\\VariableFrontend';
109+
$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['tx_dlf_pagegrid']['options']['defaultLifeTime'] = 86400; // 86400 seconds = 1 day
110+
102111
// Add new renderType for TCA fields.
103112
$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'][] = [
104113
'nodeName' => 'editInProductionWarning',

0 commit comments

Comments
 (0)