dev/core#2073 Fix a real live leak
authoreileen <emcnaughton@wikimedia.org>
Wed, 30 Sep 2020 05:44:19 +0000 (18:44 +1300)
committereileen <emcnaughton@wikimedia.org>
Wed, 30 Sep 2020 05:44:19 +0000 (18:44 +1300)
I used the same methods I had been playing with on the test class on a contribution
import script and found that the object that was increasing in memory in tandem with
me increasing iterations was an instance of DB_result

I tracked it down to here. In essence our main DAO functions clean up after themselves - e.g
when the DAO is destructed it cleans up the globals it has created.

However, this older ->query() function does not do that and each time is is called increases it's memory hold.

It's also worth better caching in this function...

CRM/ACL/BAO/ACL.php

index 873e6d55b7a7632900408e0d2b1eddb102c4e3f3..583b3dc0ce5cc7dbd52232aad92754a1a969731a 100644 (file)
@@ -204,8 +204,6 @@ SELECT      acl.*
   protected static function getGroupACLRoles($contact_id) {
     $contact_id = CRM_Utils_Type::escape($contact_id, 'Integer');
 
-    $rule = new CRM_ACL_BAO_ACL();
-
     $query = "   SELECT          acl.*
                         FROM            civicrm_acl acl
                         INNER JOIN      civicrm_option_group og
@@ -228,7 +226,7 @@ SELECT      acl.*
 
     $results = [];
 
-    $rule->query($query);
+    $rule = CRM_Core_DAO::executeQuery($query);
 
     while ($rule->fetch()) {
       $results[$rule->id] = $rule->toArray();
@@ -249,7 +247,7 @@ SELECT acl.*
    AND acl.entity_table   = 'civicrm_acl_role'
 ";
 
-    $rule->query($query);
+    $rule = CRM_Core_DAO::executeQuery($query);
     while ($rule->fetch()) {
       $results[$rule->id] = $rule->toArray();
     }