Skip to content
Snippets Groups Projects
Unverified Commit 17a063b8 authored by Seamus Lee's avatar Seamus Lee Committed by GitHub
Browse files

Merge pull request #19930 from eileenmcnaughton/acl_setting

#2477 Add setting to allow opportunistic cache flushing for acls
parents 5bf266bd 67769683
No related branches found
No related tags found
No related merge requests found
......@@ -115,10 +115,23 @@ WHERE contact_id = %1
CRM_Core_DAO::executeQuery($query, $params);
}
/**
* Do an opportunistic cache refresh if the site is configured for these.
*
* Sites that use acls and do not run the acl cache clearing cron job should
* refresh the caches on demand. The user session will be forced to wait
* and this is a common source of deadlocks, so it is less ideal.
*/
public static function opportunisticCacheFlush(): void {
if (Civi::settings()->get('acl_cache_refresh_mode') === 'opportunistic') {
self::resetCache();
}
}
/**
* Deletes all the cache entries.
*/
public static function resetCache() {
public static function resetCache(): void {
if (!CRM_Core_Config::isPermitCacheFlushMode()) {
return;
}
......
......@@ -866,7 +866,7 @@ INNER JOIN civicrm_contact contact_target ON ( contact_target.id = act.contact_i
* likely affect user experience in unexpected ways. Existing behaviour retained
* ... reluctantly.
*/
public static function clearContactCaches($isEmptyPrevNextTable = FALSE) {
public static function clearContactCaches($isEmptyPrevNextTable = FALSE): void {
if (!CRM_Core_Config::isPermitCacheFlushMode()) {
return;
}
......@@ -876,8 +876,8 @@ INNER JOIN civicrm_contact contact_target ON ( contact_target.id = act.contact_i
Civi::service('prevnext')->deleteItem();
CRM_Core_BAO_PrevNextCache::deleteItem();
}
// clear acl cache if any.
CRM_ACL_BAO_Cache::resetCache();
CRM_ACL_BAO_Cache::opportunisticCacheFlush();
CRM_Contact_BAO_GroupContactCache::opportunisticCacheFlush();
}
......
......@@ -711,21 +711,41 @@ function civicrm_api3_job_group_rebuild($params) {
/**
* Flush smart groups caches.
*
* This job purges aged smart group cache data (based on the timeout value). Sites can decide whether they want this
* job and / or the group cache rebuild job to run. In some cases performance is better when old caches are cleared out
* prior to any attempt to rebuild them. Also, many sites are very happy to have caches built on demand, provided the
* user is not having to wait for deadlocks to clear when invalidating them.
* This job purges aged smart group cache data (based on the timeout value).
* Sites can decide whether they want this job and / or the group cache rebuild
* job to run. In some cases performance is better when old caches are cleared
* out prior to any attempt to rebuild them. Also, many sites are very happy to
* have caches built on demand, provided the user is not having to wait for
* deadlocks to clear when invalidating them.
*
* @param array $params
*
* @return array
* @throws \API_Exception
* @throws \CiviCRM_API3_Exception
*/
function civicrm_api3_job_group_cache_flush($params) {
function civicrm_api3_job_group_cache_flush(array $params): array {
CRM_Contact_BAO_GroupContactCache::deterministicCacheFlush();
return civicrm_api3_create_success();
}
/**
* Flush acl caches.
*
* This job flushes the acl cache. For many sites it is better to do
* this by cron (or not at all if acls are not used) than whenever
* a contact is edited.
*
* @param array $params
*
* @return array
*
* @throws \CiviCRM_API3_Exception
*/
function civicrm_api3_job_acl_cache_flush(array $params): array {
CRM_ACL_BAO_Cache::resetCache();
return civicrm_api3_create_success();
}
/**
* Check for CiviCRM software updates.
*
......
......@@ -358,9 +358,26 @@ return [
'pseudoconstant' => [
'callback' => 'CRM_Contact_BAO_GroupContactCache::getModes',
],
'description' => ts('Should the smart groups be by cron jobs or user actions'),
'description' => ts('Should the smart groups be flushed by cron jobs or user actions'),
'help_text' => ts('In "Opportunistic Flush" mode, caches are flushed in response to user actions; this mode is broadly compatible but may add latency during form-submissions. In "Cron Flush" mode, you should schedule a cron job to flush caches; this can improve latency on form-submissions but requires more setup.'),
],
'acl_cache_refresh_mode' => [
'group_name' => 'CiviCRM Preferences',
'group' => 'core',
'name' => 'acl_cache_refresh_mode',
'type' => 'String',
'html_type' => 'radio',
'default' => 'opportunistic',
'add' => '5.37.0',
'title' => ts('ACL Group Refresh Mode'),
'is_domain' => 1,
'is_contact' => 0,
'pseudoconstant' => [
'callback' => 'CRM_Contact_BAO_GroupContactCache::getModes',
],
'description' => ts('Should the acl cache be by cron jobs or user actions'),
'help_text' => ts('In "Opportunistic Flush" mode, caches are flushed in response to user actions; this mode is broadly compatible but may add latency during form-submissions. In "Cron Flush" mode, you should schedule a cron job to flush caches if your site uses ACLs; this can improve latency on form-submissions but requires more setup.'),
],
'installed' => [
'bootstrap_comment' => 'This is a boot setting which may be loaded during bootstrap. Defaults are loaded via SettingsBag::getSystemDefaults().',
'group_name' => 'CiviCRM Preferences',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment