Commit b2b124cb authored by Stefan Froemken's avatar Stefan Froemken Committed by Christian Kuhn
Browse files

[TASK] Better performance for LiveSearch

We removed the SQL query on pages (column: pid) for TYPO3
administrators, because this group of people has access to
all pages anyway. Especially in large TYPO3 instances
the collection of all pages UIDs took a lot of time.

Resolves: #96356
Releases: main, 11.5
Change-Id: I436e15e79ce590c4228b9a9034f83497fa1db92e
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/72884


Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
parent 468b1f6a
......@@ -89,13 +89,7 @@ class LiveSearch
public function find($searchQuery)
{
$recordArray = [];
$pageList = [];
$mounts = $this->getBackendUser()->returnWebmounts();
foreach ($mounts as $pageId) {
$pageList[] = $this->getAvailablePageIds($pageId, self::RECURSIVE_PAGE_LEVEL);
}
$pageIdList = array_unique(explode(',', implode(',', $pageList)));
unset($pageList);
$pageIdList = $this->getPageIdList();
if ($this->queryParser->isValidCommand($searchQuery)) {
$this->setQueryString($this->queryParser->getSearchQueryValue($searchQuery));
$tableName = $this->queryParser->getTableNameFromCommand($searchQuery);
......@@ -109,6 +103,22 @@ class LiveSearch
return $recordArray;
}
/**
* List of available page uids for user, empty array for admin users.
*/
protected function getPageIdList(): array
{
$pageList = [];
if ($this->getBackendUser()->isAdmin()) {
return $pageList;
}
$mounts = $this->getBackendUser()->returnWebmounts();
foreach ($mounts as $pageId) {
$pageList[] = $this->getAvailablePageIds($pageId, self::RECURSIVE_PAGE_LEVEL);
}
return array_unique(explode(',', implode(',', $pageList)));
}
/**
* Find records from all registered TCA table & column values.
*
......@@ -172,15 +182,20 @@ class LiveSearch
->select('*')
->from($tableName)
->where(
$queryBuilder->expr()->in(
'pid',
$queryBuilder->createNamedParameter($pageIdList, Connection::PARAM_INT_ARRAY)
),
$this->makeQuerySearchByTable($queryBuilder, $tableName, $fieldsToSearchWithin)
)
->setFirstResult($firstResult)
->setMaxResults($maxResults);
if ($pageIdList !== []) {
$queryBuilder->andWhere(
$queryBuilder->expr()->in(
'pid',
$queryBuilder->createNamedParameter($pageIdList, Connection::PARAM_INT_ARRAY)
)
);
}
if ($tableName === 'pages' && $this->userPermissions) {
$queryBuilder->andWhere($this->userPermissions);
}
......
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