29
0
mirror of https://github.com/joomla/joomla-cms.git synced 2024-08-26 04:59:48 +00:00

[#27605] Smart Search caching issues.

This commit is contained in:
Chris Davenport 2012-01-10 17:21:27 -08:00 committed by Mark Dexter
parent 0546528249
commit 725babfa62
3 changed files with 128 additions and 127 deletions

View File

@ -43,22 +43,21 @@ class FinderController extends JController
// 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);

View File

@ -222,14 +222,10 @@ abstract class JHtmlFilter
*/
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);
@ -237,33 +233,63 @@ abstract class JHtmlFilter
$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())
@ -271,55 +297,70 @@ abstract class JHtmlFilter
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;
}
// 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;
}
// 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);
$branches[$bk]->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($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);
}
// 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 . ')');
}
// Load the branches.
$db->setQuery($sql);
$branches = $db->loadObjectList('id');
// Check for an error.
if ($db->getErrorNum())
{
return null;
}
// Check that we have at least one branch.
if (count($branches) === 0)
{
return null;
}
// Load the CSS/JS resources.
if ($loadMedia)
{
JHtml::stylesheet('com_finder/sliderfilter.css', false, true, false);
}
$html = '';
// Add the dates if enabled.
if ($showDates)
@ -329,7 +370,7 @@ abstract class JHtmlFilter
$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.
@ -337,49 +378,6 @@ abstract class JHtmlFilter
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 @@ abstract class JHtmlFilter
$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 @@ abstract class JHtmlFilter
return $html;
}
}
}

View File

@ -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.