From 2b68a50cdab2028339d5689d0f03d8037e6a9703 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Thu, 19 May 2016 16:09:23 -0700 Subject: [PATCH] CRM-16642 - Rename `refreshCache` to `flushCache` The old name is misleading about the outcome -- it does not end up producing a 'fresh' cache. It produces an empty cache. --- CRM/Activity/BAO/Activity.php | 2 +- CRM/Contact/BAO/Contact.php | 4 ++-- CRM/Contact/BAO/Contact/Utils.php | 2 +- CRM/Contact/BAO/GroupContact.php | 4 ++-- CRM/Contact/BAO/GroupContactCache.php | 10 +++++----- CRM/Contact/Form/CustomData.php | 2 +- CRM/Contact/Form/Inline/CustomData.php | 2 +- CRM/Contact/Page/AJAX.php | 2 +- CRM/Contribute/BAO/Contribution.php | 2 +- CRM/Core/BAO/EntityTag.php | 4 ++-- CRM/Event/BAO/Participant.php | 2 +- CRM/Member/BAO/Membership.php | 2 +- api/v3/Job.php | 2 +- .../CRM/Contact/BAO/GroupContactCacheTest.php | 12 ++++++------ 14 files changed, 26 insertions(+), 26 deletions(-) diff --git a/CRM/Activity/BAO/Activity.php b/CRM/Activity/BAO/Activity.php index d4027444e5..b5dbd4a440 100644 --- a/CRM/Activity/BAO/Activity.php +++ b/CRM/Activity/BAO/Activity.php @@ -584,7 +584,7 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity { } } - CRM_Contact_BAO_GroupContactCache::opportunisticCacheRefresh(); + CRM_Contact_BAO_GroupContactCache::opportunisticCacheFlush(); if (!empty($params['id'])) { CRM_Utils_Hook::post('edit', 'Activity', $activity->id, $activity); diff --git a/CRM/Contact/BAO/Contact.php b/CRM/Contact/BAO/Contact.php index 0e9dc2b34b..aa10293b57 100644 --- a/CRM/Contact/BAO/Contact.php +++ b/CRM/Contact/BAO/Contact.php @@ -935,7 +935,7 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer'); CRM_Core_DAO::executeQuery('DELETE FROM civicrm_acl_contact_cache WHERE contact_id = %1', array(1 => array($contactID, 'Integer'))); } else { - CRM_Contact_BAO_GroupContactCache::opportunisticCacheRefresh(); + CRM_Contact_BAO_GroupContactCache::opportunisticCacheFlush(); } } @@ -1932,7 +1932,7 @@ ORDER BY civicrm_email.is_primary DESC"; CRM_Contact_BAO_GroupContact::addContactsToGroup($contactIds, $addToGroupID); } - CRM_Contact_BAO_GroupContactCache::opportunisticCacheRefresh(); + CRM_Contact_BAO_GroupContactCache::opportunisticCacheFlush(); if ($editHook) { CRM_Utils_Hook::post('edit', 'Profile', $contactID, $params); diff --git a/CRM/Contact/BAO/Contact/Utils.php b/CRM/Contact/BAO/Contact/Utils.php index 5eaf2fa867..84e0c60537 100644 --- a/CRM/Contact/BAO/Contact/Utils.php +++ b/CRM/Contact/BAO/Contact/Utils.php @@ -910,7 +910,7 @@ Group By componentId"; CRM_Core_BAO_PrevNextCache::deleteItem(); } - CRM_Contact_BAO_GroupContactCache::opportunisticCacheRefresh(); + CRM_Contact_BAO_GroupContactCache::opportunisticCacheFlush(); } /** diff --git a/CRM/Contact/BAO/GroupContact.php b/CRM/Contact/BAO/GroupContact.php index 654b451380..78722e001b 100644 --- a/CRM/Contact/BAO/GroupContact.php +++ b/CRM/Contact/BAO/GroupContact.php @@ -148,7 +148,7 @@ class CRM_Contact_BAO_GroupContact extends CRM_Contact_DAO_GroupContact { // reset the group contact cache for all group(s) // if this group is being used as a smart group - CRM_Contact_BAO_GroupContactCache::opportunisticCacheRefresh(); + CRM_Contact_BAO_GroupContactCache::opportunisticCacheFlush(); CRM_Utils_Hook::post('create', 'GroupContact', $groupId, $contactIds); @@ -252,7 +252,7 @@ class CRM_Contact_BAO_GroupContact extends CRM_Contact_DAO_GroupContact { // if this group is being used as a smart group // @todo consider what to do here - it feels like we should either // 1) just invalidate the specific group's cache(& perhaps any parents) & let cron do it's thing or - // possibly clear this specific groups cache, or just call opportunisticCacheRefresh() - which would have the + // possibly clear this specific groups cache, or just call opportunisticCacheFlush() - which would have the // same effect as the remove call. The reservation about that is that it is no more aggressive for the group that // we know is altered than for all the others, or perhaps, more the point with it's parents & groups that use it in // their criteria. diff --git a/CRM/Contact/BAO/GroupContactCache.php b/CRM/Contact/BAO/GroupContactCache.php index febcee0e97..4b0ca89b86 100644 --- a/CRM/Contact/BAO/GroupContactCache.php +++ b/CRM/Contact/BAO/GroupContactCache.php @@ -416,7 +416,7 @@ WHERE id = %1 * This function should be called via the opportunistic or deterministic cache refresh function to make the intent * clear. */ - protected static function refreshCaches() { + protected static function flushCaches() { try { $lock = self::getLockForRefresh(); } @@ -492,9 +492,9 @@ WHERE id = %1 * Sites that do not run the smart group clearing cron job should refresh the caches under an opportunistic mode, akin * to a poor man's cron. The user session will be forced to wait on this so it is less desirable. */ - public static function opportunisticCacheRefresh() { + public static function opportunisticCacheFlush() { if (Civi::settings()->get('smart_group_cache_refresh_mode') == 'opportunistic') { - self::refreshCaches(); + self::flushCaches(); } } @@ -503,7 +503,7 @@ WHERE id = %1 * * This function is appropriate to be called by system jobs & non-user sessions. */ - public static function deterministicCacheRefresh() { + public static function deterministicCacheFlush() { if (self::smartGroupCacheTimeout() == 0) { CRM_Core_DAO::executeQuery("TRUNCATE civicrm_group_contact_cache"); CRM_Core_DAO::executeQuery(" @@ -511,7 +511,7 @@ WHERE id = %1 SET cache_date = null, refresh_date = null"); } else { - self::refreshCaches(); + self::flushCaches(); } } diff --git a/CRM/Contact/Form/CustomData.php b/CRM/Contact/Form/CustomData.php index 187d5fdbb6..bbb3c4e090 100644 --- a/CRM/Contact/Form/CustomData.php +++ b/CRM/Contact/Form/CustomData.php @@ -309,7 +309,7 @@ class CRM_Contact_Form_CustomData extends CRM_Core_Form { $this->ajaxResponse += CRM_Contact_Form_Inline::renderFooter($this->_tableID); } - CRM_Contact_BAO_GroupContactCache::opportunisticCacheRefresh(); + CRM_Contact_BAO_GroupContactCache::opportunisticCacheFlush(); } } diff --git a/CRM/Contact/Form/Inline/CustomData.php b/CRM/Contact/Form/Inline/CustomData.php index a21e5e1497..0c7d463027 100644 --- a/CRM/Contact/Form/Inline/CustomData.php +++ b/CRM/Contact/Form/Inline/CustomData.php @@ -97,7 +97,7 @@ class CRM_Contact_Form_Inline_CustomData extends CRM_Contact_Form_Inline { $this->log(); - CRM_Contact_BAO_GroupContactCache::opportunisticCacheRefresh(); + CRM_Contact_BAO_GroupContactCache::opportunisticCacheFlush(); $this->response(); } diff --git a/CRM/Contact/Page/AJAX.php b/CRM/Contact/Page/AJAX.php index 00aa2051ee..d39afc5da3 100644 --- a/CRM/Contact/Page/AJAX.php +++ b/CRM/Contact/Page/AJAX.php @@ -294,7 +294,7 @@ class CRM_Contact_Page_AJAX { echo CRM_Contact_BAO_Contact::getCountComponent('custom_' . $customGroupID, $contactId); } - CRM_Contact_BAO_GroupContactCache::opportunisticCacheRefresh(); + CRM_Contact_BAO_GroupContactCache::opportunisticCacheFlush(); CRM_Utils_System::civiExit(); } diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 94a3388526..0508a7116d 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -212,7 +212,7 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution { ); } - CRM_Contact_BAO_GroupContactCache::opportunisticCacheRefresh(); + CRM_Contact_BAO_GroupContactCache::opportunisticCacheFlush(); if ($contributionID) { CRM_Utils_Hook::post('edit', 'Contribution', $contribution->id, $contribution); diff --git a/CRM/Core/BAO/EntityTag.php b/CRM/Core/BAO/EntityTag.php index f3bed639a7..eec0888a27 100644 --- a/CRM/Core/BAO/EntityTag.php +++ b/CRM/Core/BAO/EntityTag.php @@ -168,7 +168,7 @@ class CRM_Core_BAO_EntityTag extends CRM_Core_DAO_EntityTag { $object = array($entityIdsAdded, $entityTable); CRM_Utils_Hook::post('create', 'EntityTag', $tagId, $object); - CRM_Contact_BAO_GroupContactCache::opportunisticCacheRefresh(); + CRM_Contact_BAO_GroupContactCache::opportunisticCacheFlush(); return array(count($entityIds), $numEntitiesAdded, $numEntitiesNotAdded); } @@ -242,7 +242,7 @@ class CRM_Core_BAO_EntityTag extends CRM_Core_DAO_EntityTag { $object = array($entityIdsRemoved, $entityTable); CRM_Utils_Hook::post('delete', 'EntityTag', $tagId, $object); - CRM_Contact_BAO_GroupContactCache::opportunisticCacheRefresh(); + CRM_Contact_BAO_GroupContactCache::opportunisticCacheFlush(); return array(count($entityIds), $numEntitiesRemoved, $numEntitiesNotRemoved); } diff --git a/CRM/Event/BAO/Participant.php b/CRM/Event/BAO/Participant.php index d0b2b0f5d7..622e96f82a 100644 --- a/CRM/Event/BAO/Participant.php +++ b/CRM/Event/BAO/Participant.php @@ -138,7 +138,7 @@ class CRM_Event_BAO_Participant extends CRM_Event_DAO_Participant { $session = CRM_Core_Session::singleton(); - CRM_Contact_BAO_GroupContactCache::opportunisticCacheRefresh(); + CRM_Contact_BAO_GroupContactCache::opportunisticCacheFlush(); if (!empty($params['id'])) { CRM_Utils_Hook::post('edit', 'Participant', $participantBAO->id, $participantBAO); diff --git a/CRM/Member/BAO/Membership.php b/CRM/Member/BAO/Membership.php index 0e4333d5c7..fabd1cc207 100644 --- a/CRM/Member/BAO/Membership.php +++ b/CRM/Member/BAO/Membership.php @@ -137,7 +137,7 @@ class CRM_Member_BAO_Membership extends CRM_Member_DAO_Membership { CRM_Member_BAO_MembershipLog::add($membershipLog, CRM_Core_DAO::$_nullArray); // reset the group contact cache since smart groups might be affected due to this - CRM_Contact_BAO_GroupContactCache::opportunisticCacheRefresh(); + CRM_Contact_BAO_GroupContactCache::opportunisticCacheFlush(); if ($id) { if ($membership->status_id != $oldStatus) { diff --git a/api/v3/Job.php b/api/v3/Job.php index cfd2ff2396..da4eb04763 100644 --- a/api/v3/Job.php +++ b/api/v3/Job.php @@ -657,7 +657,7 @@ function civicrm_api3_job_group_rebuild($params) { * @throws \API_Exception */ function civicrm_api3_job_group_cache_flush($params) { - CRM_Contact_BAO_GroupContactCache::deterministicCacheRefresh(); + CRM_Contact_BAO_GroupContactCache::deterministicCacheFlush(); return civicrm_api3_create_success(); } diff --git a/tests/phpunit/CRM/Contact/BAO/GroupContactCacheTest.php b/tests/phpunit/CRM/Contact/BAO/GroupContactCacheTest.php index bd00ca58a7..98aec5af51 100644 --- a/tests/phpunit/CRM/Contact/BAO/GroupContactCacheTest.php +++ b/tests/phpunit/CRM/Contact/BAO/GroupContactCacheTest.php @@ -169,7 +169,7 @@ class CRM_Contact_BAO_GroupContactCacheTest extends CiviUnitTestCase { array($deceased[0]->id, $deceased[1]->id, $deceased[2]->id), $group->id ); - CRM_Contact_BAO_GroupContactCache::opportunisticCacheRefresh(); + CRM_Contact_BAO_GroupContactCache::opportunisticCacheFlush(); $this->assertCacheNotRefreshed($deceased, $group); } @@ -184,7 +184,7 @@ class CRM_Contact_BAO_GroupContactCacheTest extends CiviUnitTestCase { $group->find(TRUE); Civi::$statics['CRM_Contact_BAO_GroupContactCache']['is_refresh_init'] = FALSE; sleep(1); - CRM_Contact_BAO_GroupContactCache::opportunisticCacheRefresh(); + CRM_Contact_BAO_GroupContactCache::opportunisticCacheFlush(); $this->assertCacheRefreshed($group); } @@ -197,7 +197,7 @@ class CRM_Contact_BAO_GroupContactCacheTest extends CiviUnitTestCase { $this->callAPISuccess('Setting', 'create', array('smart_group_cache_refresh_mode' => 'deterministic')); $this->callAPISuccess('Contact', 'create', array('id' => $deceased[0]->id, 'is_deceased' => 0)); $this->makeCacheStale($group); - CRM_Contact_BAO_GroupContactCache::opportunisticCacheRefresh(); + CRM_Contact_BAO_GroupContactCache::opportunisticCacheFlush(); $this->assertCacheNotRefreshed($deceased, $group); $this->callAPISuccess('Setting', 'create', array('smart_group_cache_refresh_mode' => 'opportunistic')); } @@ -210,7 +210,7 @@ class CRM_Contact_BAO_GroupContactCacheTest extends CiviUnitTestCase { $this->callAPISuccess('Setting', 'create', array('smart_group_cache_refresh_mode' => 'deterministic')); $this->callAPISuccess('Contact', 'create', array('id' => $deceased[0]->id, 'is_deceased' => 0)); $this->makeCacheStale($group); - CRM_Contact_BAO_GroupContactCache::deterministicCacheRefresh(); + CRM_Contact_BAO_GroupContactCache::deterministicCacheFlush(); $this->assertCacheRefreshed($group); $this->callAPISuccess('Setting', 'create', array('smart_group_cache_refresh_mode' => 'opportunistic')); } @@ -222,7 +222,7 @@ class CRM_Contact_BAO_GroupContactCacheTest extends CiviUnitTestCase { list($group, $living, $deceased) = $this->setupSmartGroup(); $this->callAPISuccess('Setting', 'create', array('smart_group_cache_refresh_mode' => 'deterministic')); $this->callAPISuccess('Contact', 'create', array('id' => $deceased[0]->id, 'is_deceased' => 0)); - CRM_Contact_BAO_GroupContactCache::deterministicCacheRefresh(); + CRM_Contact_BAO_GroupContactCache::deterministicCacheFlush(); $this->assertCacheNotRefreshed($deceased, $group); $this->callAPISuccess('Setting', 'create', array('smart_group_cache_refresh_mode' => 'opportunistic')); } @@ -237,7 +237,7 @@ class CRM_Contact_BAO_GroupContactCacheTest extends CiviUnitTestCase { $this->callAPISuccess('Setting', 'create', array('smart_group_cache_refresh_mode' => 'opportunistic')); $this->callAPISuccess('Contact', 'create', array('id' => $deceased[0]->id, 'is_deceased' => 0)); $this->makeCacheStale($group); - CRM_Contact_BAO_GroupContactCache::deterministicCacheRefresh(); + CRM_Contact_BAO_GroupContactCache::deterministicCacheFlush(); $this->assertCacheRefreshed($group); } -- 2.25.1