From 1416a3c475b44331dfac952afc2be76476d91da3 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Mon, 13 Jul 2020 14:26:46 -0400 Subject: [PATCH] Simplify caching of status checks and fixes missing domain_id condition Fixes a few apparent problems: - domain_id was ommitted causing unexpected results - Civi::cache was being read but never written to - Object caching did not persist in memory across different check classes - If we did write to Civi::cache there is no mechanism for clearing that cache when data changes Solution: use simple array cache in Civi::$statics --- CRM/Utils/Check/Component.php | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/CRM/Utils/Check/Component.php b/CRM/Utils/Check/Component.php index 812d75fea9..3ecf8bd347 100644 --- a/CRM/Utils/Check/Component.php +++ b/CRM/Utils/Check/Component.php @@ -18,11 +18,6 @@ use Civi\Api4\StatusPreference; */ abstract class CRM_Utils_Check_Component { - /** - * @var array - */ - public $checksConfig = []; - /** * Get the configured status checks. * @@ -32,20 +27,12 @@ abstract class CRM_Utils_Check_Component { * @throws \Civi\API\Exception\UnauthorizedException */ public function getChecksConfig() { - if (empty($this->checksConfig)) { - $this->checksConfig = Civi::cache('checks')->get('checksConfig', []); - if (empty($this->checksConfig)) { - $this->checksConfig = StatusPreference::get(FALSE)->execute()->indexBy('name'); - } + if (empty(Civi::$statics[__FUNCTION__])) { + Civi::$statics[__FUNCTION__] = (array) StatusPreference::get(FALSE) + ->addWhere('domain_id', '=', 'current_domain') + ->execute()->indexBy('name'); } - return $this->checksConfig; - } - - /** - * @param array $checksConfig - */ - public function setChecksConfig(array $checksConfig) { - $this->checksConfig = $checksConfig; + return Civi::$statics[__FUNCTION__]; } /** -- 2.25.1