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

Cache case count when getting list of cases so query is executed once instead of three times #13368

Merged
merged 1 commit into from
Dec 29, 2018
Merged
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
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