Skip to content

Commit

Permalink
Improve ACL contact cache building performance by splitting insert an…
Browse files Browse the repository at this point in the history
…d select
  • Loading branch information
seamuslee001 committed Oct 10, 2019
1 parent 32d2bb7 commit 393372a
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions CRM/Contact/BAO/Contact/Permission.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,18 @@ public static function cache($userID, $type = CRM_Core_Permission::VIEW, $force
$permission = CRM_ACL_API::whereClause($type, $tables, $whereTables, $userID, FALSE, FALSE, TRUE);

$from = CRM_Contact_BAO_Query::fromClause($whereTables);
CRM_Core_DAO::executeQuery("
INSERT INTO civicrm_acl_contact_cache ( user_id, contact_id, operation )
SELECT DISTINCT $userID as user_id, contact_a.id as contact_id, '{$operation}' as operation
$contats = CRM_Core_DAO::excuteQuery("SELECT DISTINCT $userID as user_id, contact_a.id as contact_id
$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
AND ac.user_id IS NULL
");
AND ac.user_id IS NULL");
while ($contacts->fetch()) {
CRM_Core_DAO::executeQuery("INSERT INTO civicrm_acl_contact_cache (user_id, contact_id, operation) VALUES (%1, %2, %3)", [
1 => [$contacts->user_id, 'Positive'],
2 => [$contacts->contact_id, 'Positive'],
3 => [$operation, 'String'],
]);
}

// Add in a row for the logged in contact. Do not try to combine with the above query or an ugly OR will appear in
// the permission clause.
Expand Down

0 comments on commit 393372a

Please sign in to comment.