Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(dev/core#217) PrevNext - Use more consistent cache-keys while adjusting filters #12663

Merged
merged 1 commit into from
Aug 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions CRM/Contact/Form/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,6 @@ public static function preProcessCommon(&$form) {
if ((CRM_Utils_Array::value('radio_ts', self::$_searchFormValues) == 'ts_all') ||
($form->_task == CRM_Contact_Task::SAVE_SEARCH)
) {
$sortByCharacter = $form->get('sortByCharacter');
$cacheKey = ($sortByCharacter && $sortByCharacter != 'all') ? "{$cacheKey}_alphabet" : $cacheKey;

// since we don't store all contacts in prevnextcache, when user selects "all" use query to retrieve contacts
// rather than prevnext cache table for most of the task actions except export where we rebuild query to fetch
// final result set
Expand Down
1 change: 0 additions & 1 deletion CRM/Contact/Selector.php
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,6 @@ public function buildPrevNextCache($sort) {
$countRow = Civi::service('prevnext')->getCount($cacheKey);
// $sortByCharacter triggers a refresh in the prevNext cache
if ($sortByCharacter && $sortByCharacter != 'all') {
$cacheKey .= "_alphabet";
$this->fillupPrevNextCache($sort, $cacheKey, 0, max(self::CACHE_SIZE, $pageSize));
}
elseif (($firstRecord + $pageSize) >= $countRow) {
Expand Down
30 changes: 21 additions & 9 deletions CRM/Core/PrevNextCache/Sql.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,37 +97,37 @@ public function markSelection($cacheKey, $action, $cIds = NULL) {
if (is_array($cIds)) {
$cIdFilter = "(" . implode(',', $cIds) . ")";
$whereClause = "
WHERE cacheKey LIKE %1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I confirmed that where the cacheKey is passed to this function it is always qfKey from the url - which is either the qfKey or 'civicrm search ' + $('input[name=qfKey]'

WHERE cacheKey = %1
AND (entity_id1 IN {$cIdFilter} OR entity_id2 IN {$cIdFilter})
";
}
else {
$whereClause = "
WHERE cacheKey LIKE %1
WHERE cacheKey = %1
AND (entity_id1 = %2 OR entity_id2 = %2)
";
$params[2] = array("{$cIds}", 'Integer');
}
if ($action == 'select') {
$whereClause .= "AND is_selected = 0";
$sql = "UPDATE civicrm_prevnext_cache SET is_selected = 1 {$whereClause} {$entity_whereClause}";
$params[1] = array("{$cacheKey}%", 'String');
$params[1] = array($cacheKey, 'String');
}
elseif ($action == 'unselect') {
$whereClause .= "AND is_selected = 1";
$sql = "UPDATE civicrm_prevnext_cache SET is_selected = 0 {$whereClause} {$entity_whereClause}";
$params[1] = array("%{$cacheKey}%", 'String');
$params[1] = array($cacheKey, 'String');
}
// default action is reseting
}
elseif (!$cIds && $cacheKey && $action == 'unselect') {
$sql = "
UPDATE civicrm_prevnext_cache
SET is_selected = 0
WHERE cacheKey LIKE %1 AND is_selected = 1
WHERE cacheKey = %1 AND is_selected = 1
{$entity_whereClause}
";
$params[1] = array("{$cacheKey}%", 'String');
$params[1] = array($cacheKey, 'String');
}
CRM_Core_DAO::executeQuery($sql, $params);
}
Expand Down Expand Up @@ -157,12 +157,12 @@ public function getSelection($cacheKey, $action = 'get') {
$actionGet = ($action == "get") ? " AND is_selected = 1 " : "";
$sql = "
SELECT entity_id1, entity_id2 FROM civicrm_prevnext_cache
WHERE cacheKey LIKE %1
WHERE cacheKey = %1
$actionGet
$entity_whereClause
ORDER BY id
";
$params[1] = array("{$cacheKey}%", 'String');
$params[1] = array($cacheKey, 'String');

$contactIds = array($cacheKey => array());
$cIdDao = CRM_Core_DAO::executeQuery($sql, $params);
Expand Down Expand Up @@ -199,7 +199,19 @@ public function getPositions($cacheKey, $id1, $id2) {
* @param string $entityTable
*/
public function deleteItem($id = NULL, $cacheKey = NULL, $entityTable = 'civicrm_contact') {
CRM_Core_BAO_PrevNextCache::deleteItem($id, $cacheKey, $entityTable);
$sql = "DELETE FROM civicrm_prevnext_cache WHERE entity_table = %1";
$params = array(1 => array($entityTable, 'String'));

if (is_numeric($id)) {
$sql .= " AND ( entity_id1 = %2 OR entity_id2 = %2 )";
$params[2] = array($id, 'Integer');
}

if (isset($cacheKey)) {
$sql .= " AND cacheKey = %3";
$params[3] = array($cacheKey, 'String');
}
CRM_Core_DAO::executeQuery($sql, $params);
}

/**
Expand Down