Skip to content

Commit

Permalink
Less calls
Browse files Browse the repository at this point in the history
  • Loading branch information
SharkyKZ committed Aug 26, 2019
1 parent 798abb5 commit 44456e2
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions libraries/src/Helper/ContentHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,19 @@ public static function countRelations(&$items, $config)

if ($usesWorkflows)
{
$query->from($db->quoteName('#__workflow_stages', 's'))
->from($db->quoteName('#__workflow_associations', 'a'))
->where($db->quoteName('s.id') . ' = ' . $db->quoteName('a.stage_id'))
->where($db->quoteName('a.extension') . ' = :component')
->where($db->quoteName('a.item_id') . ' = ' . $db->quoteName('c.id'))
$query->from(
[
$db->quoteName('#__workflow_stages', 's'),
$db->quoteName('#__workflow_associations', 'a'),
]
)
->where(
[
$db->quoteName('s.id') . ' = ' . $db->quoteName('a.stage_id'),
$db->quoteName('a.extension') . ' = :component',
$db->quoteName('a.item_id') . ' = ' . $db->quoteName('c.id'),
]
)
->bind(':component', $config->workflows_component);
}

Expand All @@ -132,9 +140,13 @@ public static function countRelations(&$items, $config)
* NOTE: 'state IN', allows counting specific states / conditions only, also prevents warnings with custom states / conditions, do not remove
*/
$query
->select($db->quoteName($recid_col, 'catid'))
->select($db->quoteName($state_col, 'state'))
->select('COUNT(*) AS ' . $db->quoteName('count'))
->select(
[
$db->quoteName($recid_col, 'catid'),
$db->quoteName($state_col, 'state'),
'COUNT(*) AS ' . $db->quoteName('count'),
]
)
->whereIn($db->quoteName($recid_col), array_keys($records))
->whereIn($db->quoteName($state_col), array_keys($counter_names))
->group($db->quoteName([$recid_col, $state_col]));
Expand Down

0 comments on commit 44456e2

Please sign in to comment.