From 7c8dafeab7d536acd84aeff7383d707591cb0f5e Mon Sep 17 00:00:00 2001 From: Nicola Galgano Date: Mon, 14 Mar 2016 16:04:05 +0100 Subject: [PATCH] New category count feature performance degrade #9420 part 3 --- .../com_content/helpers/content.php | 53 +++++++++++++------ 1 file changed, 37 insertions(+), 16 deletions(-) diff --git a/administrator/components/com_content/helpers/content.php b/administrator/components/com_content/helpers/content.php index 248ac85f78c81..b3d3ff2cfeada 100644 --- a/administrator/components/com_content/helpers/content.php +++ b/administrator/components/com_content/helpers/content.php @@ -70,25 +70,46 @@ public static function filterText($text) * * @since 3.4 */ - public static function countItems(&$query) + public static function countItems(&$items) { - // Join articles to categories and count published items - $query->select('COUNT(DISTINCT cp.id) AS count_published'); - $query->join('LEFT', '#__content AS cp ON cp.catid = a.id AND cp.state = 1'); + $db = JFactory::getDbo(); - // Count unpublished items - $query->select('COUNT(DISTINCT cu.id) AS count_unpublished'); - $query->join('LEFT', '#__content AS cu ON cu.catid = a.id AND cu.state = 0'); + //var_dump($this->items); + foreach ($items as $i => $item) + { + $item->count_trashed = 0; + $item->count_archived = 0; + $item->count_unpublished = 0; + $item->count_published = 0; + $query = $db->getQuery(true); + $query->select('state, count(*) AS count') + ->from($db->qn('#__content')) + ->where('catid = ' . (int) $item->id) + ->group('state'); + $db->setQuery($query); + $arts=$db->loadObjectList(); - // Count archived items - $query->select('COUNT(DISTINCT ca.id) AS count_archived'); - $query->join('LEFT', '#__content AS ca ON ca.catid = a.id AND ca.state = 2'); - - // Count trashed items - $query->select('COUNT(DISTINCT ct.id) AS count_trashed'); - $query->join('LEFT', '#__content AS ct ON ct.catid = a.id AND ct.state = -2'); - - return $query; + foreach ($arts as $i => $art) + { + if($art->state == 1) + { + $item->count_published=$art->count; + } + if($art->state == 0) + { + $item->count_unpublished=$art->count; + } + if($art->state == 2) + { + $item->count_archived=$art->count; + } + if($art->state == -2) + { + $item->count_trashed=$art->count; + } + } + } + return $items; } }