From ca83fdf95dbd7c3aa39a3b825567b256d5688856 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Tue, 7 Apr 2020 13:33:58 -0400 Subject: [PATCH] Simplify groupContactCache - remove redundant query This was essentially running the same query twice, once with COUNT and then again with INSERT. Should be ok to skip the count as the INSERT will do nothing if there are no results. --- CRM/Contact/BAO/GroupContactCache.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/CRM/Contact/BAO/GroupContactCache.php b/CRM/Contact/BAO/GroupContactCache.php index c97afa799b..9f882b6331 100644 --- a/CRM/Contact/BAO/GroupContactCache.php +++ b/CRM/Contact/BAO/GroupContactCache.php @@ -505,10 +505,7 @@ WHERE id IN ( $groupIDs ) self::clearGroupContactCache($groupID); foreach ($contactQueries as $contactQuery) { - if (empty($contactQuery['select']) || empty($contactQuery['from'])) { - continue; - } - if (CRM_Core_DAO::singleValueQuery("SELECT COUNT(*) {$contactQuery['from']}") > 0) { + if (!empty($contactQuery['select']) && !empty($contactQuery['from'])) { CRM_Core_DAO::executeQuery("INSERT IGNORE INTO $tempTable (group_id, contact_id) {$contactQuery['select']} {$contactQuery['from']}"); } } -- 2.25.1