Skip to content

Commit

Permalink
Merge pull request #13368 from mattwire/case_cachecount
Browse files Browse the repository at this point in the history
Cache case count when getting list of cases so query is executed once instead of three times
  • Loading branch information
seamuslee001 authored Dec 29, 2018
2 parents 564d6ed + d83ee56 commit 30db69d
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions CRM/Case/BAO/Case.php
Original file line number Diff line number Diff line change
Expand Up @@ -588,11 +588,16 @@ public static function getCases($allCases = TRUE, $params = array(), $context =
$condition = NULL;
$casesList = array();

//validate access for own cases.
// validate access for own cases.
if (!self::accessCiviCase()) {
return $getCount ? 0 : $casesList;
}

// Return cached value instead of re-running query
if (isset(Civi::$statics[__CLASS__]['totalCount']) && $getCount) {
return Civi::$statics[__CLASS__]['totalCount'];
}

$type = CRM_Utils_Array::value('type', $params, 'upcoming');
$userID = CRM_Core_Session::singleton()->get('userID');

Expand All @@ -610,7 +615,7 @@ public static function getCases($allCases = TRUE, $params = array(), $context =
$caseActivityIDColumn = 'case_recent_activity_id';
}

//validate access for all cases.
// validate access for all cases.
if ($allCases && !CRM_Core_Permission::check('access all cases and activities')) {
$allCases = FALSE;
}
Expand All @@ -631,7 +636,7 @@ public static function getCases($allCases = TRUE, $params = array(), $context =
}
$condition = implode(' AND ', $whereClauses);

$totalCount = CRM_Core_DAO::singleValueQuery(self::getCaseActivityCountQuery($type, $userID, $condition));
Civi::$statics[__CLASS__]['totalCount'] = $totalCount = CRM_Core_DAO::singleValueQuery(self::getCaseActivityCountQuery($type, $userID, $condition));
if ($getCount) {
return $totalCount;
}
Expand Down

0 comments on commit 30db69d

Please sign in to comment.