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);
}