From 1843d89f8de1dcbef6a308db967f3d12473e0506 Mon Sep 17 00:00:00 2001 From: Nicola Galgano Date: Wed, 14 Feb 2018 21:25:15 +0100 Subject: [PATCH 1/4] [com_content][Multilanguage] - remove duplicated queries --- .../com_content/helpers/association.php | 60 ++++++++++++------- 1 file changed, 39 insertions(+), 21 deletions(-) diff --git a/components/com_content/helpers/association.php b/components/com_content/helpers/association.php index 462dc0593fcb9..1f2d55fee56e4 100644 --- a/components/com_content/helpers/association.php +++ b/components/com_content/helpers/association.php @@ -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 * @@ -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)) + ->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(); } } - return $return; + return static::$filters[$id]; } } From 5da224d4374878b47de60910df0cfc2c94daa3ba Mon Sep 17 00:00:00 2001 From: Nicola Galgano Date: Wed, 14 Feb 2018 21:41:44 +0100 Subject: [PATCH 2/4] cs --- components/com_content/helpers/association.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/com_content/helpers/association.php b/components/com_content/helpers/association.php index 1f2d55fee56e4..7902418625e67 100644 --- a/components/com_content/helpers/association.php +++ b/components/com_content/helpers/association.php @@ -84,7 +84,7 @@ public static function getAssociations($id = 0, $view = null) if (count($associations) === 0) { - static::$filters[$id] =array(); + static::$filters[$id] = array(); } } From 9d756fbdc79904bcae877c29aea4b74dbbde79d6 Mon Sep 17 00:00:00 2001 From: Nicola Galgano Date: Sat, 17 Feb 2018 08:42:33 +0100 Subject: [PATCH 3/4] add $db->qn() --- components/com_content/helpers/association.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/com_content/helpers/association.php b/components/com_content/helpers/association.php index 7902418625e67..221e87552c799 100644 --- a/components/com_content/helpers/association.php +++ b/components/com_content/helpers/association.php @@ -68,7 +68,7 @@ public static function getAssociations($id = 0, $view = null) ->select($db->qn('state')) ->from($db->qn('#__content')) ->where($db->qn('id') . ' = ' . (int) ($assocId)) - ->where('access IN (' . $groups . ')'); + ->where($db->qn('access') . ' IN (' . $groups . ')'); $db->setQuery($query); $result = (int) $db->loadResult(); From c6766e4d69c8cecbb3f41ee831356ba1e33de4ee Mon Sep 17 00:00:00 2001 From: Nicola Galgano Date: Sat, 17 Feb 2018 12:49:08 +0100 Subject: [PATCH 4/4] removed () --- components/com_content/helpers/association.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/com_content/helpers/association.php b/components/com_content/helpers/association.php index 221e87552c799..f823bacea2f1c 100644 --- a/components/com_content/helpers/association.php +++ b/components/com_content/helpers/association.php @@ -67,7 +67,7 @@ public static function getAssociations($id = 0, $view = null) $query = $db->getQuery(true) ->select($db->qn('state')) ->from($db->qn('#__content')) - ->where($db->qn('id') . ' = ' . (int) ($assocId)) + ->where($db->qn('id') . ' = ' . (int) $assocId) ->where($db->qn('access') . ' IN (' . $groups . ')'); $db->setQuery($query);