Cache CRM_ACL_BAO_ACL::entityTable per-request
authorAdam Roses Wight <awight@wikimedia.org>
Tue, 23 Apr 2013 21:16:28 +0000 (14:16 -0700)
committerAdam Roses Wight <awight@wikimedia.org>
Tue, 23 Apr 2013 21:27:04 +0000 (14:27 -0700)
CRM/ACL/BAO/ACL.php

index 5cb31b53065a897bc0251bca020fe3c9c55a54a1..ba54b1d2a75c5d5a7c6d659db02354e0fae513b0 100644 (file)
@@ -837,7 +837,11 @@ SELECT g.*
       $aclKeys = array_keys($acls);
       $aclKeys = implode(',', $aclKeys);
 
-      $query = "
+      $cacheKey = "$tableName-$aclKeys";
+      $cache = CRM_Utils_Cache::singleton();
+      $ids = $cache->get($cacheKey);
+      if (!$ids) {
+        $query = "
 SELECT   a.operation, a.object_id
   FROM   civicrm_acl_cache c, civicrm_acl a
  WHERE   c.acl_id       =  a.id
@@ -847,24 +851,26 @@ SELECT   a.operation, a.object_id
 GROUP BY a.operation,a.object_id
 ORDER BY a.object_id
 ";
-      $params = array(1 => array($tableName, 'String'));
-      $dao = CRM_Core_DAO::executeQuery($query, $params);
-      while ($dao->fetch()) {
-        if ($dao->object_id) {
-          if (self::matchType($type, $dao->operation)) {
-            $ids[] = $dao->object_id;
+        $params = array(1 => array($tableName, 'String'));
+        $dao = CRM_Core_DAO::executeQuery($query, $params);
+        while ($dao->fetch()) {
+          if ($dao->object_id) {
+            if (self::matchType($type, $dao->operation)) {
+              $ids[] = $dao->object_id;
+            }
           }
-        }
-        else {
-          // this user has got the permission for all objects of this type
-          // check if the type matches
-          if (self::matchType($type, $dao->operation)) {
-            foreach ($allGroups as $id => $dontCare) {
-              $ids[] = $id;
+          else {
+            // this user has got the permission for all objects of this type
+            // check if the type matches
+            if (self::matchType($type, $dao->operation)) {
+              foreach ($allGroups as $id => $dontCare) {
+                $ids[] = $id;
+              }
             }
+            break;
           }
-          break;
         }
+        $cache->set($cacheKey, $ids);
       }
     }