Skip to content

Commit

Permalink
Merge pull request #14324 from eileenmcnaughton/dedupe_cleanup2
Browse files Browse the repository at this point in the history
[REF] Extract function to get cached duplicate matches
  • Loading branch information
mattwire authored May 25, 2019
2 parents 148b2b7 + 4107e11 commit 30ebe68
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions CRM/Dedupe/Merger.php
Original file line number Diff line number Diff line change
Expand Up @@ -1833,17 +1833,14 @@ public static function createMergeActivities($mainId, $otherId) {
* @throws \CiviCRM_API3_Exception
*/
public static function getDuplicatePairs($rule_group_id, $group_id, $reloadCacheIfEmpty, $batchLimit, $isSelected, $includeConflicts = TRUE, $criteria = [], $checkPermissions = TRUE, $searchLimit = 0) {
$where = self::getWhereString($isSelected);
$cacheKeyString = self::getMergeCacheKeyString($rule_group_id, $group_id, $criteria, $checkPermissions);
$join = self::getJoinOnDedupeTable();
$dupePairs = CRM_Core_BAO_PrevNextCache::retrieve($cacheKeyString, $join, $where, 0, $batchLimit, [], '', $includeConflicts);
$dupePairs = self::getCachedDuplicateMatches($rule_group_id, $group_id, $batchLimit, $isSelected, $includeConflicts, $criteria, $checkPermissions);
if (empty($dupePairs) && $reloadCacheIfEmpty) {
$cacheKeyString = CRM_Dedupe_Merger::getMergeCacheKeyString($rule_group_id, $group_id, $criteria, $checkPermissions);
// 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, $searchLimit);
$dupePairs = CRM_Core_BAO_PrevNextCache::retrieve($cacheKeyString, $join, $where, 0, $batchLimit, [], '', $includeConflicts);
return $dupePairs;
return self::getCachedDuplicateMatches($rule_group_id, $group_id, $batchLimit, $isSelected, FALSE, $criteria, $checkPermissions);
}
return $dupePairs;
}
Expand Down Expand Up @@ -2451,4 +2448,26 @@ protected static function processCustomFieldFiles($mainId, $otherId, $customFile
}
}

/**
* @param $rule_group_id
* @param $group_id
* @param $batchLimit
* @param $isSelected
* @param $includeConflicts
* @param $criteria
* @param $checkPermissions
*
* @return array
*/
protected static function getCachedDuplicateMatches($rule_group_id, $group_id, $batchLimit, $isSelected, $includeConflicts, $criteria, $checkPermissions) {
return CRM_Core_BAO_PrevNextCache::retrieve(
self::getMergeCacheKeyString($rule_group_id, $group_id, $criteria, $checkPermissions),
self::getJoinOnDedupeTable(),
self::getWhereString($isSelected),
0, $batchLimit,
[], '',
$includeConflicts
);
}

}

0 comments on commit 30ebe68

Please sign in to comment.