X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FContact%2FBAO%2FGroup.php;h=b0cea18aa89201e1df4a0b3d5a27b268d5818a04;hb=1b9976cbf762dbf6513df8a4141626d2e5584171;hp=1ad8a313b8bdee676b598fcd1675e36a07d30b49;hpb=8ea180b7e15f28bc58a8cffa5378fb6337cb955c;p=civicrm-core.git diff --git a/CRM/Contact/BAO/Group.php b/CRM/Contact/BAO/Group.php index 1ad8a313b8..b0cea18aa8 100644 --- a/CRM/Contact/BAO/Group.php +++ b/CRM/Contact/BAO/Group.php @@ -965,13 +965,15 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group { } } - // Get group counts + // Get group counts - executes one query for regular groups and another for smart groups foreach ($groupsToCount as $table => $groups) { - $where = "group_id IN (" . implode(',', $groups) . ")"; + $where = "g.group_id IN (" . implode(',', $groups) . ")"; if ($table == 'civicrm_group_contact') { - $where .= " AND status = 'Added'"; + $where .= " AND g.status = 'Added'"; } - $dao = CRM_Core_DAO::executeQuery("SELECT group_id, COUNT(id) as `count` FROM $table WHERE $where GROUP BY group_id"); + // Exclude deleted contacts + $where .= " and c.id = g.contact_id AND c.is_deleted = 0"; + $dao = CRM_Core_DAO::executeQuery("SELECT g.group_id, COUNT(g.id) as `count` FROM $table g, civicrm_contact c WHERE $where GROUP BY g.group_id"); while ($dao->fetch()) { $values[$dao->group_id]['count'] = $dao->count; }