From 10a7c252fd7a32e2b5f917f930929af042a30e50 Mon Sep 17 00:00:00 2001 From: Matthew Wire Date: Sat, 30 Oct 2021 18:08:25 +0100 Subject: [PATCH] Simplify and improve performance of query to insert updated cache --- CRM/Contact/BAO/GroupContactCache.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/CRM/Contact/BAO/GroupContactCache.php b/CRM/Contact/BAO/GroupContactCache.php index 0fb98d5dbc..dc96a88935 100644 --- a/CRM/Contact/BAO/GroupContactCache.php +++ b/CRM/Contact/BAO/GroupContactCache.php @@ -765,9 +765,13 @@ ORDER BY gc.contact_id, g.children private static function updateCacheFromTempTable(CRM_Utils_SQL_TempTable $groupContactsTempTable, array $groupIDs): void { $tempTable = $groupContactsTempTable->getName(); + // @fixme: GROUP BY is here to guard against having duplicate contacts in the temptable. + // That used to happen for an unknown reason and probably doesn't anymore so we *should* + // be able to remove GROUP BY here safely. CRM_Core_DAO::executeQuery( - "INSERT IGNORE INTO civicrm_group_contact_cache (contact_id, group_id) - SELECT DISTINCT contact_id, group_id FROM $tempTable + "INSERT INTO civicrm_group_contact_cache (contact_id, group_id) + SELECT contact_id, group_id FROM $tempTable + GROUP BY contact_id,group_id "); $groupContactsTempTable->drop(); foreach ($groupIDs as $groupID) { -- 2.25.1