Skip to content

Commit

Permalink
Merge pull request #13394 from totten/master-srchcache
Browse files Browse the repository at this point in the history
(dev/core#635) Reduce unnecessary SQL writes
  • Loading branch information
colemanw authored Jan 8, 2019
2 parents c8115b6 + e37c68e commit 9360fd2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 4 additions & 2 deletions CRM/Campaign/Selector/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,10 @@ public function buildPrevNextCache($sort) {
return;
}

// also record an entry in the cache key table, so we can delete it periodically
CRM_Core_BAO_Cache::setItem($cacheKey, 'CiviCRM Search PrevNextCache', $cacheKey);
if (Civi::service('prevnext') instanceof CRM_Core_PrevNextCache_Sql) {
// SQL-backed prevnext cache uses an extra record for pruning the cache.
CRM_Core_BAO_Cache::setItem($cacheKey, 'CiviCRM Search PrevNextCache', $cacheKey);
}
}
}

Expand Down
10 changes: 6 additions & 4 deletions CRM/Contact/Selector.php
Original file line number Diff line number Diff line change
Expand Up @@ -536,11 +536,11 @@ public function &getColumnHeaders($action = NULL, $output = NULL) {
public function getTotalCount($action) {
// Use count from cache during paging/sorting
if (!empty($_GET['crmPID']) || !empty($_GET['crmSID'])) {
$count = CRM_Core_BAO_Cache::getItem('Search Results Count', $this->_key);
$count = Civi::cache('long')->get("Search Results Count $this->_key");
}
if (empty($count)) {
$count = $this->_query->searchQuery(0, 0, NULL, TRUE);
CRM_Core_BAO_Cache::setItem($count, 'Search Results Count', $this->_key);
Civi::cache('long')->set("Search Results Count $this->_key", $count);
}
return $count;
}
Expand Down Expand Up @@ -1062,8 +1062,10 @@ public function fillupPrevNextCache($sort, $cacheKey, $start = 0, $end = self::C
}
}

// also record an entry in the cache key table, so we can delete it periodically
CRM_Core_BAO_Cache::setItem($cacheKey, 'CiviCRM Search PrevNextCache', $cacheKey);
if (Civi::service('prevnext') instanceof CRM_Core_PrevNextCache_Sql) {
// SQL-backed prevnext cache uses an extra record for pruning the cache.
CRM_Core_BAO_Cache::setItem($cacheKey, 'CiviCRM Search PrevNextCache', $cacheKey);
}
}

/**
Expand Down

0 comments on commit 9360fd2

Please sign in to comment.