From c93f3d19924f4467d76f8d62bd7db4f495cde76b Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Mon, 2 Jul 2018 16:57:51 -0700 Subject: [PATCH] (dev/core#217) PrevNext - Allow swapping `getCount()` for purposes of 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`.) --- CRM/Contact/Selector.php | 2 +- CRM/Core/PrevNextCache/Interface.php | 8 ++++++++ CRM/Core/PrevNextCache/Sql.php | 10 ++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/CRM/Contact/Selector.php b/CRM/Contact/Selector.php index 945c2b3162..066e4a4476 100644 --- a/CRM/Contact/Selector.php +++ b/CRM/Contact/Selector.php @@ -900,7 +900,7 @@ class CRM_Contact_Selector extends CRM_Core_Selector_Base implements CRM_Core_Se $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"; diff --git a/CRM/Core/PrevNextCache/Interface.php b/CRM/Core/PrevNextCache/Interface.php index 57742338f0..c71b57ed24 100644 --- a/CRM/Core/PrevNextCache/Interface.php +++ b/CRM/Core/PrevNextCache/Interface.php @@ -104,4 +104,12 @@ interface CRM_Core_PrevNextCache_Interface { */ public function deleteItem($id = NULL, $cacheKey = NULL, $entityTable = 'civicrm_contact'); + /** + * Get count of matching rows. + * + * @param string $cacheKey + * @return int + */ + public function getCount($cacheKey); + } diff --git a/CRM/Core/PrevNextCache/Sql.php b/CRM/Core/PrevNextCache/Sql.php index c9a26a187d..2f20a63ba9 100644 --- a/CRM/Core/PrevNextCache/Sql.php +++ b/CRM/Core/PrevNextCache/Sql.php @@ -202,4 +202,14 @@ ORDER BY id 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'"); + } + } -- 2.25.1