CRM-18120 make acl query less debilitating
authoreileenmcnaugton <eileen@fuzion.co.nz>
Mon, 29 Feb 2016 05:48:46 +0000 (18:48 +1300)
committereileenmcnaugton <eileen@fuzion.co.nz>
Mon, 24 Oct 2016 02:17:49 +0000 (15:17 +1300)
CRM/Contact/BAO/Contact/Permission.php

index 432339166b7a515cd1653be432a016f705b23910..bbdc30ea2c6c4107bf63ca8343000cdfa2ee755a 100644 (file)
@@ -234,19 +234,14 @@ AND    $operationClause
     $permission = CRM_ACL_API::whereClause($type, $tables, $whereTables, $userID);
 
     $from = CRM_Contact_BAO_Query::fromClause($whereTables);
-
-    // FIXME: don't use 'ON DUPLICATE KEY UPDATE'
     CRM_Core_DAO::executeQuery("
 INSERT INTO civicrm_acl_contact_cache ( user_id, contact_id, operation )
-SELECT      $userID as user_id, contact_a.id as contact_id, '$operation' as operation
+SELECT DISTINCT $userID as user_id, contact_a.id as contact_id, '{$operation}' as operation
          $from
+         LEFT JOIN civicrm_acl_contact_cache ac ON ac.user_id = $userID AND ac.contact_id = contact_a.id AND ac.operation = '{$operation}'
 WHERE    $permission
-GROUP BY contact_a.id
-ON DUPLICATE KEY UPDATE
-         user_id=VALUES(user_id),
-         contact_id=VALUES(contact_id),
-         operation=VALUES(operation)"
-    );
+AND ac.user_id IS NULL
+");
     $_processed[$type][$userID] = 1;
   }