Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OPTIMIZATION] Add pagegrid caching #8

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Classes/Controller/AbstractController.php
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ private function getDocumentByUid(int $documentId)
$this->document = $this->documentRepository->findOneByIdAndSettings($documentId);

if ($this->document) {
$doc = AbstractDocument::getInstance($this->document->getLocation(), $this->settings, true);
$doc = AbstractDocument::getInstance($this->document->getLocation(), $this->settings, false);
} else {
$this->logger->error('Invalid UID "' . $documentId . '" or PID "' . $this->settings['storagePid'] . '" for document loading');
}
Expand Down
33 changes: 23 additions & 10 deletions Classes/Controller/PageGridController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Kitodo\Dlf\Pagination\PageGridPagination;
use Kitodo\Dlf\Pagination\PageGridPaginator;
use TYPO3\CMS\Core\Cache\CacheManager;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
Expand Down Expand Up @@ -43,19 +44,31 @@ public function mainAction(): void
return;
}

$entryArray = [];

$numPages = $this->document->getCurrentDocument()->numPages;
// Iterate through visible page set and display thumbnails.
for ($i = 1; $i <= $numPages; $i++) {
$foundEntry = $this->getEntry($i, $this->extConf['files']['fileGrpThumbs']);
$foundEntry['state'] = ($i == $this->requestData['page']) ? 'cur' : 'no';
$entryArray[] = $foundEntry;
}

// Get current page from request data because the parameter is shared between plugins
$currentPage = $this->requestData['page'] ?? 1;

// access cachemanager for pagegrid
$cacheManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Cache\CacheManager::class);
$cache = $cacheManager->getCache('tx_dlf_pagegrid');
$cacheKey = $this->document->getCurrentDocument()->recordId;
$cachedData = $cache->get($cacheKey);

if ($cachedData) {
$entryArray = $cachedData; //load from cache
} else {
$numPages = $this->document->getCurrentDocument()->numPages;

for ($i = 1; $i <= $numPages; $i++) {
$foundEntry = $this->getEntry($i, $this->extConf['files']['fileGrpThumbs']);
$foundEntry['state'] = 'no';
$entryArray[] = $foundEntry;
}

$cache->set($cacheKey, $entryArray, [], 86400);
}
// mark currently active page
$entryArray[$currentPage - 1]['state'] = 'cur';

$itemsPerPage = $this->settings['paginate']['itemsPerPage'];
if (empty($itemsPerPage)) {
$itemsPerPage = 25;
Expand Down
9 changes: 9 additions & 0 deletions ext_localconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,15 @@
if (!isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['tx_dlf_doc']['options']['defaultLifeTime'])) {
$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['tx_dlf_doc']['options']['defaultLifeTime'] = 86400; // 86400 seconds = 1 day
}
// Use Caching Framework for PageGrid $entryArray caching
$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['tx_dlf_pagegrid'] ??= [];

if (!isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['tx_dlf_pagegrid']['backend'])) {
$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['tx_dlf_pagegrid']['backend'] = 'TYPO3\\CMS\\Core\\Cache\\Backend\\FileBackend';
}
$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['tx_dlf_pagegrid']['frontend'] = 'TYPO3\\CMS\\Core\\Cache\\Frontend\\VariableFrontend';
$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['tx_dlf_pagegrid']['options']['defaultLifeTime'] = 86400; // 86400 seconds = 1 day

// Add new renderType for TCA fields.
$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'][] = [
'nodeName' => 'editInProductionWarning',
Expand Down
Loading