From 411f09c9593f004042e74c0bf93953e6756fd0d4 Mon Sep 17 00:00:00 2001 From: eileen Date: Wed, 7 Oct 2020 18:35:49 +1300 Subject: [PATCH] dev/core#2073 Remove memory leak in heavily tested (merge) code There are dozens of tests that pass through these lines - I used api_v3_JobTest:testBatchMerge to step through it - note the dao->affectedRows uses a query to determine that - so it is no more or less accurate than before --- CRM/Dedupe/BAO/RuleGroup.php | 5 ++--- CRM/Dedupe/Finder.php | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/CRM/Dedupe/BAO/RuleGroup.php b/CRM/Dedupe/BAO/RuleGroup.php index 5e1258e775..6cbb407c84 100644 --- a/CRM/Dedupe/BAO/RuleGroup.php +++ b/CRM/Dedupe/BAO/RuleGroup.php @@ -212,7 +212,6 @@ class CRM_Dedupe_BAO_RuleGroup extends CRM_Dedupe_DAO_RuleGroup { $patternColumn = '/t1.(\w+)/'; $exclWeightSum = []; - $dao = new CRM_Core_DAO(); CRM_Utils_Hook::dupeQuery($this, 'table', $tableQueries); while (!empty($tableQueries)) { @@ -257,7 +256,7 @@ class CRM_Dedupe_BAO_RuleGroup extends CRM_Dedupe_DAO_RuleGroup { // construct and execute the intermediate query $query = "{$insertClause} {$query} {$groupByClause} ON DUPLICATE KEY UPDATE weight = weight + VALUES(weight)"; - $dao->query($query); + $dao = CRM_Core_DAO::executeQuery($query); // FIXME: we need to be more acurate with affected rows, especially for insert vs duplicate insert. // And that will help optimize further. @@ -279,7 +278,7 @@ class CRM_Dedupe_BAO_RuleGroup extends CRM_Dedupe_DAO_RuleGroup { $fieldWeight = $fieldWeight[0]; $query = array_shift($tableQueries); $query = "{$insertClause} {$query} {$groupByClause} ON DUPLICATE KEY UPDATE weight = weight + VALUES(weight)"; - $dao->query($query); + $dao = CRM_Core_DAO::executeQuery($query); if ($dao->affectedRows() >= 1) { $exclWeightSum[] = substr($fieldWeight, strrpos($fieldWeight, '.') + 1); } diff --git a/CRM/Dedupe/Finder.php b/CRM/Dedupe/Finder.php index 52f6dc4a81..a6d670e03c 100644 --- a/CRM/Dedupe/Finder.php +++ b/CRM/Dedupe/Finder.php @@ -47,13 +47,12 @@ class CRM_Dedupe_Finder { } $rgBao->fillTable(); - $dao = new CRM_Core_DAO(); - $dao->query($rgBao->thresholdQuery($checkPermissions)); + $dao = CRM_Core_DAO::executeQuery($rgBao->thresholdQuery($checkPermissions)); $dupes = []; while ($dao->fetch()) { $dupes[] = [$dao->id1, $dao->id2, $dao->weight]; } - $dao->query($rgBao->tableDropQuery()); + CRM_Core_DAO::executeQuery(($rgBao->tableDropQuery())); return $dupes; } -- 2.25.1