From: Eileen McNaughton Date: Thu, 18 Aug 2022 00:22:48 +0000 (+1200) Subject: Further fix on has X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=a065eac7eeec5b4942bddc3f94d6a80c41c586e7;p=civicrm-core.git Further fix on has --- diff --git a/CRM/Utils/Cache/FastArrayDecorator.php b/CRM/Utils/Cache/FastArrayDecorator.php index 00e2c24697..67ebe54c4f 100644 --- a/CRM/Utils/Cache/FastArrayDecorator.php +++ b/CRM/Utils/Cache/FastArrayDecorator.php @@ -119,7 +119,17 @@ class CRM_Utils_Cache_FastArrayDecorator implements CRM_Utils_Cache_Interface { if (array_key_exists($key, $this->values)) { return TRUE; } - return $this->delegate->has($key); + // Doing a get here populates `$this->values`. If the calling + // code does a `has()` followed by a `get` we want only one + // look-up so do that lookup on the first request. + // (The only real reason to do `has` & then `get` is it is + // less ambiguous for false & empty values) + // `$this->delegate->has($key)` here then an extra + // lookup will be needed if we do `has` followed by `get`. + // Reducing `get` calls to the underlying cache has significant + // speed improvement (see https://github.com/civicrm/civicrm-core/pull/24156) + $this->get($key); + return array_key_exists($key, $this->values); } }