Eileen has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/381311 )

Change subject: CRM-21224 reinstate use of limit on dedupe searches
......................................................................

CRM-21224 reinstate use of limit on dedupe searches

https://github.com/civicrm/civicrm-core/pull/11030

I'm not sure this is the last we'll hear of this but I'm sure this is at
least part of the fix

Bug: T175382
Change-Id: Ice270d01d8d9033ff9db3f18c1762544b8bfaa79
---
M CRM/Contact/Page/DedupeFind.php
M CRM/Core/BAO/PrevNextCache.php
M CRM/Dedupe/Finder.php
M CRM/Dedupe/Merger.php
4 files changed, 28 insertions(+), 15 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/crm/civicrm 
refs/changes/11/381311/1

diff --git a/CRM/Contact/Page/DedupeFind.php b/CRM/Contact/Page/DedupeFind.php
index decfdbc..41fa2ea 100644
--- a/CRM/Contact/Page/DedupeFind.php
+++ b/CRM/Contact/Page/DedupeFind.php
@@ -157,7 +157,7 @@
         CRM_Dedupe_Merger::resetMergeStats($cacheKeyString);
       }
 
-      $this->_mainContacts = CRM_Dedupe_Merger::getDuplicatePairs($rgid, $gid, 
!$isConflictMode, 0, $isConflictMode, '', $isConflictMode, $criteria, TRUE);
+      $this->_mainContacts = CRM_Dedupe_Merger::getDuplicatePairs($rgid, $gid, 
!$isConflictMode, 0, $isConflictMode, '', $isConflictMode, $criteria, TRUE, 
$limit);
 
       if (empty($this->_mainContacts)) {
         if ($isConflictMode) {
diff --git a/CRM/Core/BAO/PrevNextCache.php b/CRM/Core/BAO/PrevNextCache.php
index a3d6f44..0eab40d 100644
--- a/CRM/Core/BAO/PrevNextCache.php
+++ b/CRM/Core/BAO/PrevNextCache.php
@@ -366,11 +366,16 @@
    * @param bool $checkPermissions
    *   Respect logged in user's permissions.
    *
+   * @param int $searchLimit
+   *  Limit for the number of contacts to be used for comparison.
+   *  The search methodology finds all matches for the searchedContacts so 
this limits
+   *  the number of searched contacts, not the matches found.
+   *
    * @return bool
    * @throws \CRM_Core_Exception
    * @throws \CiviCRM_API3_Exception
    */
-  public static function refillCache($rgid, $gid, $cacheKeyString, $criteria, 
$checkPermissions) {
+  public static function refillCache($rgid, $gid, $cacheKeyString, $criteria, 
$checkPermissions, $searchLimit = 0) {
     if (!$cacheKeyString && $rgid) {
       $cacheKeyString = CRM_Dedupe_Merger::getMergeCacheKeyString($rgid, $gid, 
$criteria, $checkPermissions);
     }
@@ -389,7 +394,7 @@
     // 2. FILL cache
     $foundDupes = array();
     if ($rgid && $gid) {
-      $foundDupes = CRM_Dedupe_Finder::dupesInGroup($rgid, $gid);
+      $foundDupes = CRM_Dedupe_Finder::dupesInGroup($rgid, $gid, $searchLimit);
     }
     elseif ($rgid) {
       $contactIDs = array();
@@ -397,7 +402,7 @@
         $contacts = civicrm_api3('Contact', 'get', array_merge(array('options' 
=> array('limit' => 0), 'return' => 'id'), $criteria['contact']));
         $contactIDs = array_keys($contacts['values']);
       }
-      $foundDupes = CRM_Dedupe_Finder::dupes($rgid, $contactIDs, 
$checkPermissions);
+      $foundDupes = CRM_Dedupe_Finder::dupes($rgid, $contactIDs, 
$checkPermissions, $searchLimit);
     }
 
     if (!empty($foundDupes)) {
diff --git a/CRM/Dedupe/Finder.php b/CRM/Dedupe/Finder.php
index 4504447..aa092e4 100644
--- a/CRM/Dedupe/Finder.php
+++ b/CRM/Dedupe/Finder.php
@@ -51,9 +51,10 @@
    * @param bool $checkPermissions
    *   Respect logged in user permissions.
    *
-   * @param int $limit
-   *   Optional limit. This limits the number of contacts for which the code 
will
-   *   attempt to find matches.
+   * @param int $searchLimit
+   *  Limit for the number of contacts to be used for comparison.
+   *  The search methodology finds all matches for the searchedContacts so 
this limits
+   *  the number of searched contacts, not the matches found.
    *
    * @return array
    *   Array of (cid1, cid2, weight) dupe triples
@@ -61,18 +62,18 @@
    * @throws CiviCRM_API3_Exception
    * @throws Exception
    */
-  public static function dupes($rgid, $cids = array(), $checkPermissions = 
TRUE, $limit = NULL) {
+  public static function dupes($rgid, $cids = array(), $checkPermissions = 
TRUE, $searchLimit = 0) {
     $rgBao = new CRM_Dedupe_BAO_RuleGroup();
     $rgBao->id = $rgid;
     $rgBao->contactIds = $cids;
     if (!$rgBao->find(TRUE)) {
       CRM_Core_Error::fatal("Dedupe rule not found for selected contacts");
     }
-    if (empty($rgBao->contactIds) && !empty($limit)) {
+    if (empty($rgBao->contactIds) && !empty($searchLimit)) {
       $limitedContacts = civicrm_api3('Contact', 'get', array(
         'return' => 'id',
         'contact_type' => $rgBao->contact_type,
-        'options' => array('limit' => $limit),
+        'options' => array('limit' => $searchLimit),
       ));
       $rgBao->contactIds = array_keys($limitedContacts['values']);
     }
@@ -167,12 +168,16 @@
    * @param int $gid
    *   Contact group id (currently, works only with non-smart groups).
    *
-   * @param int $limit
+   * @param int $searchLimit
+   *  Limit for the number of contacts to be used for comparison.
+   *  The search methodology finds all matches for the searchedContacts so 
this limits
+   *  the number of searched contacts, not the matches found.
+   *
    * @return array
    *   array of (cid1, cid2, weight) dupe triples
    */
-  public static function dupesInGroup($rgid, $gid, $limit = NULL) {
-    $cids = array_keys(CRM_Contact_BAO_Group::getMember($gid, $limit));
+  public static function dupesInGroup($rgid, $gid, $searchLimit = 0) {
+    $cids = array_keys(CRM_Contact_BAO_Group::getMember($gid, $searchLimit));
     if (!empty($cids)) {
       return self::dupes($rgid, $cids);
     }
diff --git a/CRM/Dedupe/Merger.php b/CRM/Dedupe/Merger.php
index 96ff298..13d37bc 100644
--- a/CRM/Dedupe/Merger.php
+++ b/CRM/Dedupe/Merger.php
@@ -1888,10 +1888,13 @@
    * @param bool $checkPermissions
    *   Respect logged in user permissions.
    *
+   * @param int $searchLimit
+   *   Limit to searching for matches against this many contacts.
+   *
    * @return array
    *    Array of matches meeting the criteria.
    */
-  public static function getDuplicatePairs($rule_group_id, $group_id, 
$reloadCacheIfEmpty, $batchLimit, $isSelected, $orderByClause = '', 
$includeConflicts = TRUE, $criteria = array(), $checkPermissions = TRUE) {
+  public static function getDuplicatePairs($rule_group_id, $group_id, 
$reloadCacheIfEmpty, $batchLimit, $isSelected, $orderByClause = '', 
$includeConflicts = TRUE, $criteria = array(), $checkPermissions = TRUE, 
$searchLimit = 0) {
     $where = self::getWhereString($batchLimit, $isSelected);
     $cacheKeyString = self::getMergeCacheKeyString($rule_group_id, $group_id, 
$criteria, $checkPermissions);
     $join = self::getJoinOnDedupeTable();
@@ -1900,7 +1903,7 @@
       // If we haven't found any dupes, probably cache is empty.
       // Try filling cache and give another try. We don't need to specify 
include conflicts here are there will not be any
       // until we have done some processing.
-      CRM_Core_BAO_PrevNextCache::refillCache($rule_group_id, $group_id, 
$cacheKeyString, $criteria, $checkPermissions);
+      CRM_Core_BAO_PrevNextCache::refillCache($rule_group_id, $group_id, 
$cacheKeyString, $criteria, $checkPermissions, $searchLimit);
       $dupePairs = CRM_Core_BAO_PrevNextCache::retrieve($cacheKeyString, 
$join, $where, 0, 0, array(), $orderByClause, $includeConflicts);
       return $dupePairs;
     }

-- 
To view, visit https://gerrit.wikimedia.org/r/381311
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ice270d01d8d9033ff9db3f18c1762544b8bfaa79
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/crm/civicrm
Gerrit-Branch: master
Gerrit-Owner: Eileen <emcnaugh...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to