Permalink
Browse files

[#27605] Smart Search caching issues.

  • Loading branch information...
1 parent 0546528 commit 725babfa627e9ccf6269ecc3995318f1d305215e Chris Davenport committed with dextercowley Jan 11, 2012
Showing with 123 additions and 122 deletions.
  1. +9 −10 components/com_finder/controller.php
  2. +113 −112 components/com_finder/helpers/html/filter.php
  3. +1 −0 installation/CHANGELOG
@@ -43,22 +43,21 @@ public function display($cachable = false, $urlparams = array())
// Load plug-in language files.
FinderHelperLanguage::loadPluginLanguage();
+ // Load plug-in language files.
+ FinderHelperLanguage::loadPluginLanguage();
+
// Set the default view name and format from the Request.
$viewName = $input->get('view', 'search', 'word');
$input->set('view', $viewName);
- if ($user->get('id') || ($_SERVER['REQUEST_METHOD'] == 'POST' && $viewName = 'search'))
- {
- $cachable = false;
- }
+ // Don't cache view for search queries
+ if ($input->get('q') || $input->get('f') || $input->get('t')) {
+ $cachable = false;
+ }
$safeurlparams = array(
- 'id' => 'INT',
- 'limit' => 'INT',
- 'limitstart' => 'INT',
- 'filter_order' => 'CMD',
- 'filter_order_Dir' => 'CMD',
- 'lang' => 'CMD'
+ 'f' => 'INT',
+ 'lang' => 'CMD'
);
return parent::display($cachable, $safeurlparams);
@@ -222,105 +222,146 @@ public static function slider($options = array())
*/
public static function select($query, $options)
{
- $db = JFactory::getDBO();
- $sql = $db->getQuery(true);
- $user = JFactory::getUser();
- $app = JFactory::getApplication();
+ $user = JFactory::getUser();
$groups = implode(',', $user->getAuthorisedViewLevels());
- $html = '';
- $in = '';
$filter = null;
+ $app = JFactory::getApplication();
// Get the configuration options.
$classSuffix = $options->get('class_suffix', null);
$loadMedia = $options->get('load_media', true);
$showDates = $options->get('show_date_filters', false);
// Try to load the results from cache.
- //@TODO: Alternate for $aid
- $cache = JFactory::getCache('com_finder', 'output');
- $key = 'filter_select_' . serialize(array( /*$aid,*/ $query, $options));
- $data = unserialize((string) $cache->get($key));
+ $cache = JFactory::getCache('com_finder', '');
+ $cacheId = 'filter_select_' . serialize(array($query->filter, $options, $groups, JFactory::getLanguage()->getTag()));
// Check the cached results.
- if ($data !== false && !empty($data))
+ if (!($branches = $cache->get($cacheId)))
{
- // Load the CSS/JS resources.
- if ($loadMedia)
+ $db = JFactory::getDBO();
+ $sql = $db->getQuery(true);
+
+ // Load the predefined filter if specified.
+ if (!empty($query->filter))
{
- JHtml::stylesheet('com_finder/sliderfilter.css', false, true, false);
+ $sql->select($db->quoteName('f') . '.' . $db->quoteName('data') . ', '. $db->quoteName('f') . '.' . $db->quoteName('params'));
+ $sql->from($db->quoteName('#__finder_filters') . ' AS f');
+ $sql->where($db->quoteName('f') . '.' . $db->quoteName('filter_id') . ' = ' . (int) $query->filter);
+
+ // Load the filter data.
+ $db->setQuery($sql);
+ $filter = $db->loadObject();
+
+ // Check for an error.
+ if ($db->getErrorNum())
+ {
+ return null;
+ }
+
+ // Initialize the filter parameters.
+ if ($filter)
+ {
+ $registry = new JRegistry;
+ $registry->loadString($filter->params);
+ $filter->params = $registry;
+ }
}
- return $data;
- }
+ // Build the query to get the branch data and the number of child nodes.
+ $sql->clear();
+ $sql->select('t.*, count(c.id) AS children');
+ $sql->from($db->quoteName('#__finder_taxonomy') . ' AS t');
+ $sql->join('INNER', $db->quoteName('#__finder_taxonomy') . ' AS c ON c.parent_id = t.id');
+ $sql->where($db->quoteName('t') . '.' . $db->quoteName('parent_id') . ' = 1');
+ $sql->where($db->quoteName('t') . '.' . $db->quoteName('state') . ' = 1');
+ $sql->where($db->quoteName('t') . '.' . $db->quoteName('access') . ' IN (' . $groups . ')');
+ $sql->where($db->quoteName('c') . '.' . $db->quoteName('state') . ' = 1');
+ $sql->where($db->quoteName('t') . '.' . $db->quoteName('access') . ' IN (' . $groups . ')');
+ $sql->group($db->quoteName('t') . '.' . $db->quoteName('id'));
+ $sql->order('t.ordering, t.title');
- // Load the predefined filter if specified.
- if (!empty($query->filter))
- {
- $sql->select($db->quoteName('f') . '.' . $db->quoteName('data') . ', '. $db->quoteName('f') . '.' . $db->quoteName('params'));
- $sql->from($db->quoteName('#__finder_filters') . ' AS f');
- $sql->where($db->quoteName('f') . '.' . $db->quoteName('filter_id') . ' = ' . (int) $query->filter);
+ // Limit the branch children to a predefined filter.
+ if (!empty($filter->data))
+ {
+ $sql->where('c.id IN(' . $filter->data . ')');
+ }
- // Load the filter data.
+ // Load the branches.
$db->setQuery($sql);
- $filter = $db->loadObject();
+ $branches = $db->loadObjectList('id');
// Check for an error.
if ($db->getErrorNum())
{
return null;
}
- // Initialize the filter parameters.
- if ($filter)
+ // Check that we have at least one branch.
+ if (count($branches) === 0)
{
- $registry = new JRegistry;
- $registry->loadString($filter->params);
- $filter->params = $registry;
+ return null;
}
- }
- // Build the query to get the branch data and the number of child nodes.
- $sql->clear();
- $sql->select('t.*, count(c.id) AS children');
- $sql->from($db->quoteName('#__finder_taxonomy') . ' AS t');
- $sql->join('INNER', $db->quoteName('#__finder_taxonomy') . ' AS c ON c.parent_id = t.id');
- $sql->where($db->quoteName('t') . '.' . $db->quoteName('parent_id') . ' = 1');
- $sql->where($db->quoteName('t') . '.' . $db->quoteName('state') . ' = 1');
- $sql->where($db->quoteName('t') . '.' . $db->quoteName('access') . ' IN (' . $groups . ')');
- $sql->where($db->quoteName('c') . '.' . $db->quoteName('state') . ' = 1');
- $sql->where($db->quoteName('t') . '.' . $db->quoteName('access') . ' IN (' . $groups . ')');
- $sql->group($db->quoteName('t') . '.' . $db->quoteName('id'));
- $sql->order('t.ordering, t.title');
- // Limit the branch children to a predefined filter.
- if (!empty($filter->data))
- {
- $sql->where('c.id IN(' . $filter->data . ')');
- }
+ // Iterate through the branches and build the branch groups.
+ foreach ($branches as $bk => $bv)
+ {
+ // If the multi-lang plug-in is enabled then drop the language branch.
+ if ($bv->title == 'Language' && $app->isSite() && $app->getLanguageFilter()) {
+ continue;
+ }
- // Load the branches.
- $db->setQuery($sql);
- $branches = $db->loadObjectList('id');
+ // Build the query to get the child nodes for this branch.
+ $sql->clear();
+ $sql->select('t.*');
+ $sql->from($db->quoteName('#__finder_taxonomy') . ' AS t');
+ $sql->where($db->quoteName('t') . '.' . $db->quoteName('parent_id') . ' = ' . (int) $bk);
+ $sql->where($db->quoteName('t') . '.' . $db->quoteName('state') . ' = 1');
+ $sql->where($db->quoteName('t') . '.' . $db->quoteName('access') . ' IN (' . $groups . ')');
+ $sql->order('t.ordering, t.title');
+
+ // Limit the nodes to a predefined filter.
+ if (!empty($filter->data))
+ {
+ $sql->where('t.id IN(' . $filter->data . ')');
+ }
- // Check for an error.
- if ($db->getErrorNum())
- {
- return null;
- }
+ // Load the branches.
+ $db->setQuery($sql);
+ $branches[$bk]->nodes = $db->loadObjectList('id');
- // Check that we have at least one branch.
- if (count($branches) === 0)
- {
- return null;
- }
+ // Check for an error.
+ if ($db->getErrorNum())
+ {
+ return null;
+ }
- // Load the CSS/JS resources.
- if ($loadMedia)
- {
- JHtml::stylesheet('com_finder/sliderfilter.css', false, true, false);
+ // Skip the branch if less than two nodes are available.
+ if (count($branches[$bk]->nodes) < 2)
+ {
+ continue;
+ }
+
+ // Translate branch nodes if possible.
+ $language = JFactory::getLanguage();
+ foreach($branches[$bk]->nodes as $node_id => $node) {
+ $key = FinderHelperLanguage::branchPlural($node->title);
+ if ($language->hasKey($key)) {
+ $branches[$bk]->nodes[$node_id]->title = JText::_($key);
+ }
+ }
+
+ // Add the Search All option to the branch.
+ array_unshift($branches[$bk]->nodes, array('id' => null, 'title' => JText::_('COM_FINDER_FILTER_SELECT_ALL_LABEL')));
+ }
+
+ // Store the data in cache.
+ $cache->store($branches, $cacheId);
}
+ $html = '';
+
// Add the dates if enabled.
if ($showDates)
{
@@ -329,57 +370,14 @@ public static function select($query, $options)
$html .= '<ul id="finder-filter-select-list">';
- // Iterate through the branches and build the branch groups.
+ // Iterate through all branches and build code.
foreach ($branches as $bk => $bv)
{
// If the multi-lang plug-in is enabled then drop the language branch.
if ($bv->title == 'Language' && $app->isSite() && $app->getLanguageFilter()) {
continue;
}
- // Build the query to get the child nodes for this branch.
- $sql->clear();
- $sql->select('t.*');
- $sql->from($db->quoteName('#__finder_taxonomy') . ' AS t');
- $sql->where($db->quoteName('t') . '.' . $db->quoteName('parent_id') . ' = ' . (int) $bk);
- $sql->where($db->quoteName('t') . '.' . $db->quoteName('state') . ' = 1');
- $sql->where($db->quoteName('t') . '.' . $db->quoteName('access') . ' IN (' . $groups . ')');
- $sql->order('t.ordering, t.title');
-
- // Limit the nodes to a predefined filter.
- if (!empty($filter->data))
- {
- $sql->where('t.id IN(' . $filter->data . ')');
- }
-
- // Load the branches.
- $db->setQuery($sql);
- $nodes = $db->loadObjectList('id');
-
- // Check for an error.
- if ($db->getErrorNum())
- {
- return null;
- }
-
- // Skip the branch if less than two nodes are available.
- if (count($nodes) < 2)
- {
- continue;
- }
-
- // Translate node titles if possible.
- $lang = JFactory::getLanguage();
- foreach ($nodes as $node_id => $node) {
- $key = FinderHelperLanguage::branchPlural($node->title);
- if ($lang->hasKey($key)) {
- $nodes[$node_id]->title = JText::_($key);
- }
- }
-
- // Add the Search All option to the branch.
- array_unshift($nodes, array('id' => null, 'title' => JText::_('COM_FINDER_FILTER_SELECT_ALL_LABEL')));
-
$active = null;
// Check if the branch is in the filter.
@@ -397,15 +395,18 @@ public static function select($query, $options)
$html .= '<label for="tax-' . JFilterOutput::stringUrlSafe($bv->title) . '">';
$html .= JText::sprintf('COM_FINDER_FILTER_BRANCH_LABEL', JText::_(FinderHelperLanguage::branchSingular($bv->title)));
$html .= '</label>';
- $html .= JHtml::_('select.genericlist', $nodes, 't[]', 'class="inputbox"', 'id', 'title', $active, 'tax-' . JFilterOutput::stringUrlSafe($bv->title));
+ $html .= JHtml::_('select.genericlist', $branches[$bk]->nodes, 't[]', 'class="inputbox"', 'id', 'title', $active, 'tax-' . JFilterOutput::stringUrlSafe($bv->title));
$html .= '</li>';
}
// Close the widget.
$html .= '</ul>';
- // Store the output in cache.
- $cache->store(serialize($html), $key);
+ // Load the CSS/JS resources.
+ if ($loadMedia)
+ {
+ JHtml::stylesheet('com_finder/sliderfilter.css', false, true, false);
+ }
return $html;
}
@@ -472,4 +473,4 @@ public static function dates($query, $options)
return $html;
}
-}
+}
View
@@ -53,6 +53,7 @@ $ -> Language fix or change
# [#27681] Database check feature improvements
# [#27656] Backward compatibility issue with JRules() and JRule()
# [#27638] Web links metadata fields missing from user interface
+ # [#27605] Smart Search caching issues.
09-Jan-2012 Jean-Marie Simonet
# [#27671] Hathor Global configuration not working. Thanks Andrea.

0 comments on commit 725babf

Please sign in to comment.