Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[com_content][Multilanguage] - remove duplicated queries #19683

Merged
merged 4 commits into from
Apr 22, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 39 additions & 21 deletions components/com_content/helpers/association.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@
*/
abstract class ContentHelperAssociation extends CategoryHelperAssociation
{
/**
* Cached array of the content item id.
*
* @var array
* @since __DEPLOY_VERSION__
*/
protected static $filters = array();

/**
* Method to get the associations for a given item
*
Expand All @@ -42,35 +50,45 @@ public static function getAssociations($id = 0, $view = null)
{
if ($id)
{
$associations = JLanguageAssociations::getAssociations('com_content', '#__content', 'com_content.item', $id);

$return = array();

foreach ($associations as $tag => $item)
if (!isset(static::$filters[$id]))
{
if ($item->language != JFactory::getLanguage()->getTag())
{
$arrId = explode(':', $item->id);
$assocId = $arrId[0];
$associations = JLanguageAssociations::getAssociations('com_content', '#__content', 'com_content.item', $id);

$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select($db->qn('state'))
->from($db->qn('#__content'))
->where($db->qn('id') . ' = ' . (int) ($assocId))
->where('access IN (' . $groups . ')');
$db->setQuery($query);
$return = array();

$result = (int) $db->loadResult();

if ($result > 0)
foreach ($associations as $tag => $item)
{
if ($item->language != JFactory::getLanguage()->getTag())
{
$return[$tag] = ContentHelperRoute::getArticleRoute($item->id, (int) $item->catid, $item->language);
$arrId = explode(':', $item->id);
$assocId = $arrId[0];

$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select($db->qn('state'))
->from($db->qn('#__content'))
->where($db->qn('id') . ' = ' . (int) ($assocId))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove () from ($assocId)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

->where('access IN (' . $groups . ')');
$db->setQuery($query);

$result = (int) $db->loadResult();

if ($result > 0)
{
$return[$tag] = ContentHelperRoute::getArticleRoute($item->id, (int) $item->catid, $item->language);
}
}

static::$filters[$id] = $return;
}

if (count($associations) === 0)
{
static::$filters[$id] =array();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add space after =

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}
}

return $return;
return static::$filters[$id];
}
}

Expand Down