Merge pull request #21943 from mattwire/gccacheignore
authordemeritcowboy <demeritcowboy@hotmail.com>
Mon, 25 Apr 2022 16:14:51 +0000 (12:14 -0400)
committerGitHub <noreply@github.com>
Mon, 25 Apr 2022 16:14:51 +0000 (12:14 -0400)
Simplify and improve performance of query to insert updated cache

1  2 
CRM/Contact/BAO/GroupContactCache.php

index e32acb047c24d72c8613aa8bea0f3d59cc164d8f,dc96a8893549e4a737449dd21007ce2d9231f45d..1c709c1047cb8080dd9748cd4d0b6816cc5592df
@@@ -767,10 -765,15 +767,14 @@@ ORDER BY   gc.contact_id, g.childre
    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) {
        self::updateCacheTime([$groupID], TRUE);
      }