From b8eae4bd35fda8ec82a4443663dc6b697ed86ae9 Mon Sep 17 00:00:00 2001 From: eileen Date: Wed, 4 Sep 2013 11:35:09 +1200 Subject: [PATCH] CRM-9493 - improve performance on group contact cache build (fixed & re-submitted) --- CRM/Contact/BAO/GroupContactCache.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/CRM/Contact/BAO/GroupContactCache.php b/CRM/Contact/BAO/GroupContactCache.php index 90b2cdd62f..9e40ef412f 100644 --- a/CRM/Contact/BAO/GroupContactCache.php +++ b/CRM/Contact/BAO/GroupContactCache.php @@ -480,16 +480,22 @@ WHERE civicrm_group_contact.status = 'Added' $groupIDs = array($groupID); self::remove($groupIDs); - $processed = FALSE; + $tempTable = 'civicrm_temp_group_contact_cache' . rand(0,2000); foreach (array($sql, $sqlB) as $selectSql) { if (!$selectSql) { continue; } - $insertSql = "INSERT IGNORE INTO civicrm_group_contact_cache (group_id,contact_id) ($selectSql);"; + $insertSql = "CREATE TEMPORARY TABLE $tempTable ($selectSql);"; $processed = TRUE; $result = CRM_Core_DAO::executeQuery($insertSql); + CRM_Core_DAO::executeQuery( + "INSERT IGNORE INTO civicrm_group_contact_cache (contact_id, group_id) + SELECT DISTINCT id, group_id FROM $tempTable + "); + CRM_Core_DAO::executeQuery(" DROP TABLE $tempTable"); } + self::updateCacheTime($groupIDs, $processed); if ($group->children) { -- 2.25.1