Skip to content

Commit

Permalink
Removed the magic number 500.
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnFF committed Oct 14, 2016
1 parent 65e49eb commit 450941a
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions CRM/Contact/Selector.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
*/
class CRM_Contact_Selector extends CRM_Core_Selector_Base implements CRM_Core_Selector_API {

const CACHE_SIZE = 500;

/**
* This defines two actions- View and Edit.
*
Expand Down Expand Up @@ -901,10 +903,10 @@ public function buildPrevNextCache($sort) {
// $sortByCharacter triggers a refresh in the prevNext cache
if ($sortByCharacter && $sortByCharacter != 'all') {
$cacheKey .= "_alphabet";
$this->fillupPrevNextCache($sort, $cacheKey, 0, max(500, $pageSize));
$this->fillupPrevNextCache($sort, $cacheKey, 0, max(self::CACHE_SIZE, $pageSize));
}
elseif (($firstRecord + $pageSize) >= $countRow) {
$this->fillupPrevNextCache($sort, $cacheKey, $countRow, max(500, $pageSize) + $firstRecord - $countRow);
$this->fillupPrevNextCache($sort, $cacheKey, $countRow, max(self::CACHE_SIZE, $pageSize) + $firstRecord - $countRow);
}
return $cacheKey;
}
Expand Down Expand Up @@ -1020,7 +1022,7 @@ public function removeActions(&$rows) {
* @param int $start
* @param int $end
*/
public function fillupPrevNextCache($sort, $cacheKey, $start = 0, $end = 500) {
public function fillupPrevNextCache($sort, $cacheKey, $start = 0, $end = self::CACHE_SIZE) {
$coreSearch = TRUE;
// For custom searches, use the contactIDs method
if (is_a($this, 'CRM_Contact_Selector_Custom')) {
Expand Down Expand Up @@ -1090,7 +1092,7 @@ public function rebuildPreNextCache($start, $end, $sort, $cacheKey) {

$dao = CRM_Core_DAO::executeQuery($sql);

// build insert query, note that currently we build cache for 500 contact records at a time, hence below approach
// build insert query, note that currently we build cache for 500 (self::CACHE_SIZE) contact records at a time, hence below approach
$insertValues = array();
while ($dao->fetch()) {
$insertValues[] = "('civicrm_contact', {$dao->contact_id}, {$dao->contact_id}, '{$cacheKey}', '" . CRM_Core_DAO::escapeString($dao->sort_name) . "')";
Expand Down

0 comments on commit 450941a

Please sign in to comment.