Skip to content

Commit 2ef3e3c

Browse files
authored
[5.4] Optimize smart search module (#45347)
Smart Search module creates new Query and triggers `Joomla\Component\Finder\Administrator\Indexer::processString()` method which loads available taxonomy branch titles via separate SQL query per each module (duplicate query). We should not process empty string, when the module is loaded without any input. Plus, `Taxonomy::getBranchTitles()` load should use static cache and produce only single query to prevent duplicate when we have multiple mod_finder instances (i.e. typical case for Yootheme templates where one module is rendered in header and second in mobile dialog).
1 parent b52b408 commit 2ef3e3c

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

administrator/components/com_finder/src/Indexer/Query.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -733,8 +733,10 @@ protected function processDates($date1, $date2, $when1, $when2)
733733
*/
734734
protected function processString($input, $lang, $mode)
735735
{
736-
if ($input === null) {
737-
$input = '';
736+
$input = trim($input ?? '');
737+
738+
if ($input === '') {
739+
return true;
738740
}
739741

740742
// Clean up the input string.

administrator/components/com_finder/src/Indexer/Taxonomy.php

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -306,23 +306,29 @@ public static function addMap($linkId, $nodeId)
306306
*/
307307
public static function getBranchTitles()
308308
{
309-
$db = Factory::getDbo();
309+
static $titles;
310310

311-
// Set user variables
312-
$groups = implode(',', Factory::getUser()->getAuthorisedViewLevels());
311+
if ($titles === null) {
312+
$db = Factory::getDbo();
313313

314-
// Create a query to get the taxonomy branch titles.
315-
$query = $db->getQuery(true)
316-
->select($db->quoteName('title'))
317-
->from($db->quoteName('#__finder_taxonomy'))
318-
->where($db->quoteName('parent_id') . ' = 1')
319-
->where($db->quoteName('state') . ' = 1')
320-
->where($db->quoteName('access') . ' IN (' . $groups . ')');
314+
// Set user variables
315+
$groups = implode(',', Factory::getUser()->getAuthorisedViewLevels());
321316

322-
// Get the branch titles.
323-
$db->setQuery($query);
317+
// Create a query to get the taxonomy branch titles.
318+
$query = $db->getQuery(true)
319+
->select($db->quoteName('title'))
320+
->from($db->quoteName('#__finder_taxonomy'))
321+
->where($db->quoteName('parent_id') . ' = 1')
322+
->where($db->quoteName('state') . ' = 1')
323+
->where($db->quoteName('access') . ' IN (' . $groups . ')');
324+
325+
// Get the branch titles.
326+
$db->setQuery($query);
327+
328+
$titles = $db->loadColumn();
329+
}
324330

325-
return $db->loadColumn();
331+
return $titles;
326332
}
327333

328334
/**

0 commit comments

Comments
 (0)