Skip to content

Commit

Permalink
Merge remote-tracking branch 'colemanw/cache'
Browse files Browse the repository at this point in the history
[#41] Simplify caching, more efficient managed reconcile
  • Loading branch information
jensschuppe committed Apr 19, 2022
2 parents bf1af0a + 74ac911 commit f1ea640
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
8 changes: 5 additions & 3 deletions CRM/Eck/BAO/EckEntityType.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ class CRM_Eck_BAO_EckEntityType extends CRM_Eck_DAO_EckEntityType {
* @return array[]
*/
public static function getEntityTypes(): array {
if (!isset(Civi::$statics['EckEntityTypes'])) {
Civi::$statics['EckEntityTypes'] = CRM_Core_DAO::executeQuery(
$entityTypes = Civi::cache('metadata')->get('EckEntityTypes');
if (!is_array($entityTypes)) {
$entityTypes = CRM_Core_DAO::executeQuery(
'SELECT *, CONCAT("Eck_", name) AS entity_name, CONCAT("civicrm_eck_", LOWER(name)) AS table_name FROM `civicrm_eck_entity_type`;'
)->fetchAll();
Civi::cache('metadata')->set('EckEntityTypes', $entityTypes);
}
return Civi::$statics['EckEntityTypes'];
return $entityTypes;
}

/**
Expand Down
10 changes: 5 additions & 5 deletions eck.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ function eck_civicrm_xmlMenu(&$files) {
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_managed
*/
function eck_civicrm_managed(&$entities) {
function eck_civicrm_managed(&$entities, $modules = NULL) {
if ($modules && !in_array(E::LONG_NAME, $modules, TRUE)) {
return;
}
// Scan the managed/ directory for .mgd.php files
_eck_civix_civicrm_managed($entities);

Expand Down Expand Up @@ -202,16 +205,13 @@ function eck_civicrm_post($action, $entity, $id, $object) {
CRM_Eck_BAO_EckEntityType::ensureEntityType($object->toArray());
}

// Reset cache of entity types
Civi::$statics['EckEntityTypes'] = NULL;

// Flush schema cache.
CRM_Core_DAO_AllCoreTables::reinitializeCache();
Civi::cache('metadata')->clear();

// Refresh managed entities which are autogenerated based on EckEntities
// @see eck_civicrm_managed()
\CRM_Core_ManagedEntities::singleton()->reconcile();
\CRM_Core_ManagedEntities::singleton()->reconcile(E::LONG_NAME);

// Flush navigation cache.
CRM_Core_BAO_Navigation::resetNavigation();
Expand Down

0 comments on commit f1ea640

Please sign in to comment.