Skip to content

Commit

Permalink
New category count feature performance degrade #9420
Browse files Browse the repository at this point in the history
part 3
  • Loading branch information
alikon committed Mar 14, 2016
1 parent 04b0193 commit 7c8dafe
Showing 1 changed file with 37 additions and 16 deletions.
53 changes: 37 additions & 16 deletions administrator/components/com_content/helpers/content.php
Expand Up @@ -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;
}

}

0 comments on commit 7c8dafe

Please sign in to comment.