From a7718acbe04134efd4f7b67626c44d17f26b2ead Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Tue, 14 Jul 2020 03:13:19 -0700 Subject: [PATCH] hook_civicrm_entityTypes - Remove superfluous early-stage invocation Before ------ TLDR: There are superfluous queries+hooks in every bootstrap. Specifically: * During early stages of bootstrap, the extension system loads the `CRM_Extension_Manager_*` classes. * The constructors for these classes lookup the option-group IDs in anticipation that they'll beeded. * The lookup uses a helper method which relies on `hook_entityTypes`. * Since all this happens during early bootstrap, `hook_entityTypes` becomes a preboot hook. * But it's silly - because we don't actually these groupIds. They're only used during installation/uninstallation of obscure extensions. After ----- TLDR: Less superfluous queries+hooks. * The `CRM_Extension_Manager_*` classes do not trigger any extraneous OG lookkups during bootstrap. * The `CRM_Extension_Manager_*` will only do the query when it really needs to. * `hook_entityTypes` fires later in bootstrap - when more services are available. --- CRM/Extension/Manager/Report.php | 9 ++++++--- CRM/Extension/Manager/Search.php | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/CRM/Extension/Manager/Report.php b/CRM/Extension/Manager/Report.php index bd8b5d67a7..da14a38b21 100644 --- a/CRM/Extension/Manager/Report.php +++ b/CRM/Extension/Manager/Report.php @@ -24,7 +24,10 @@ class CRM_Extension_Manager_Report extends CRM_Extension_Manager_Base { */ public function __construct() { parent::__construct(TRUE); - $this->groupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', + } + + public function getGroupId() { + return CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', self::REPORT_GROUP_NAME, 'id', 'name' ); } @@ -51,7 +54,7 @@ class CRM_Extension_Manager_Report extends CRM_Extension_Manager_Base { throw new CRM_Core_Exception(ts('Component for which you are trying to install the extension (%1) is currently disabled.', [1 => $info->typeInfo['component']])); } $weight = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', - ['option_group_id' => $this->groupId] + ['option_group_id' => $this->getGroupId()] ); $params = [ 'label' => $info->label . ' (' . $info->key . ')', @@ -60,7 +63,7 @@ class CRM_Extension_Manager_Report extends CRM_Extension_Manager_Base { 'weight' => $weight, 'description' => $info->label . ' (' . $info->key . ')', 'component_id' => $compId, - 'option_group_id' => $this->groupId, + 'option_group_id' => $this->getGroupId(), 'is_active' => 1, ]; diff --git a/CRM/Extension/Manager/Search.php b/CRM/Extension/Manager/Search.php index d498711f52..13ec3bca1e 100644 --- a/CRM/Extension/Manager/Search.php +++ b/CRM/Extension/Manager/Search.php @@ -24,7 +24,10 @@ class CRM_Extension_Manager_Search extends CRM_Extension_Manager_Base { */ public function __construct() { parent::__construct(TRUE); - $this->groupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', + } + + public function getGroupId() { + return CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', self::CUSTOM_SEARCH_GROUP_NAME, 'id', 'name' ); } @@ -42,11 +45,11 @@ class CRM_Extension_Manager_Search extends CRM_Extension_Manager_Base { } $weight = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', - ['option_group_id' => $this->groupId] + ['option_group_id' => $this->getGroupId()] ); $params = [ - 'option_group_id' => $this->groupId, + 'option_group_id' => $this->getGroupId(), 'weight' => $weight, 'description' => $info->label . ' (' . $info->key . ')', 'name' => $info->key, -- 2.25.1