Skip to content

Commit

Permalink
(dev/core#217) PrevNext - Allow swapping getCount() for purposes of…
Browse files Browse the repository at this point in the history
… contact-search

The `getCount()` function is used by both contact-search and dedupe-merge use-cases.

* Contact-search
    * `CRM/Contact/Selector.php:            $countRow = CRM_Core_BAO_PrevNextCache::getCount($cacheKey, NULL, "entity_table = 'civicrm_contact'");`
* Dedupe-merge
    * `CRM/Contact/Page/AJAX.php:           $iTotal   = CRM_Core_BAO_PrevNextCache::getCount($cacheKeyString, $join, $whereClause, '=', $queryParams);`
    * `CRM/Contact/Page/DedupeMerge.php:    $total    = CRM_Core_BAO_PrevNextCache::getCount($cacheKeyString, NULL, ($onlyProcessSelected ? "pn.is_selected = 1" : NULL));`

Our aim in developing `CRM_Core_PrevNextCache_Interface` is to allow contact-search to swap a MySQL
backend with a Redis backend -- and dedupe-merge should continue as-is (whether or not Redis is
available).  This basically means:

* Contact-search switches to using `Civi::service('prevnext')->getCount()`
* Dedupe-merge continues using `CRM_Core_BAO_PrevNextCache::getCount()`

Note that the `Interface::getCount()` is simpler than the BAO's variant. This is good because:

* Contact-search doesn't need as many parameters.
* Dedupe-merge still needs all the parameters.
* Adding all parameters would make it hard to implement on other backends. (This is esp true of SQL-style options `$join` and `$where`.)
  • Loading branch information
totten committed Jul 3, 2018
1 parent 7218b16 commit 3a647a0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CRM/Contact/Selector.php
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,7 @@ public function buildPrevNextCache($sort) {
$sortByCharacter = CRM_Utils_Request::retrieve('sortByCharacter', 'String');

//for text field pagination selection save
$countRow = CRM_Core_BAO_PrevNextCache::getCount($cacheKey, NULL, "entity_table = 'civicrm_contact'");
$countRow = Civi::service('prevnext')->getCount($cacheKey);
// $sortByCharacter triggers a refresh in the prevNext cache
if ($sortByCharacter && $sortByCharacter != 'all') {
$cacheKey .= "_alphabet";
Expand Down
8 changes: 8 additions & 0 deletions CRM/Core/PrevNextCache/Interface.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,12 @@ public function getPositions($cacheKey, $id1, $id2);
*/
public function deleteItem($id = NULL, $cacheKey = NULL, $entityTable = 'civicrm_contact');

/**
* Get count of matching rows.
*
* @param string $cacheKey
* @return int
*/
public function getCount($cacheKey);

}
10 changes: 10 additions & 0 deletions CRM/Core/PrevNextCache/Sql.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,14 @@ public function deleteItem($id = NULL, $cacheKey = NULL, $entityTable = 'civicrm
CRM_Core_BAO_PrevNextCache::deleteItem($id, $cacheKey, $entityTable);
}

/**
* Get count of matching rows.
*
* @param string $cacheKey
* @return int
*/
public function getCount($cacheKey) {
return CRM_Core_BAO_PrevNextCache::getCount($cacheKey, NULL, "entity_table = 'civicrm_contact'");
}

}

0 comments on commit 3a647a0

Please sign in to comment.