Commit 2b898bc9 authored by Christoph Lehmann's avatar Christoph Lehmann Committed by Stefan Bürk
Browse files

[TASK] Use runtime cache in `PageRepository::getPageOverlaysForLanguage()`

The function is called several times during menu/page generation with
the same arguments.

Its query results are now cached in the runtime cache to spend less
time doing SQL queries.

This streamlines the behaviour in default lanuage where
`PageRepository::getPage()` already uses the runtime cache.

Resolves: #97525
Releases: main
Change-Id: I2515e66f8bfd102cc5c9ed624c75a4b91b3084b5
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/77235


Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Reviewed-by: Stefan Bürk's avatarStefan Bürk <stefan@buerk.tech>
Tested-by: Stefan Bürk's avatarStefan Bürk <stefan@buerk.tech>
Tested-by: Georg Ringer's avatarGeorg Ringer <georg.ringer@gmail.com>
Reviewed-by: Georg Ringer's avatarGeorg Ringer <georg.ringer@gmail.com>
parent 80e573f4
......@@ -618,7 +618,7 @@ class PageRepository implements LoggerAwareInterface
$candidates = [];
$maxChunk = PlatformInformation::getMaxBindParameters($queryBuilder->getConnection()->getDatabasePlatform());
foreach (array_chunk($pageUids, (int)floor($maxChunk / 3)) as $pageUidsChunk) {
$result = $queryBuilder
$query = $queryBuilder
->select('*')
->from('pages')
->where(
......@@ -630,10 +630,18 @@ class PageRepository implements LoggerAwareInterface
$transOrigPointerField,
$queryBuilder->createNamedParameter($pageUidsChunk, Connection::PARAM_INT_ARRAY)
)
)->executeQuery();
);
// This has cache hits for the current page and for menus (little performance gain).
$cacheIdentifier = 'PageRepository_getPageOverlaysForLanguage_'
. hash('xxh3', $query->getSQL() . json_encode($query->getParameters()));
$rows = $this->getRuntimeCache()->get($cacheIdentifier);
if (!is_array($rows)) {
$rows = $query->executeQuery()->fetchAllAssociative();
$this->getRuntimeCache()->set($cacheIdentifier, $rows);
}
// Fetch and bring in priority order
while ($row = $result->fetchAssociative()) {
foreach ($rows as $row) {
$pageId = $row[$transOrigPointerField];
$priority = array_search($row[$languageField], $languageUids);
$candidates[$pageId][$priority] = $row;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment