[MediaWiki-commits] [Gerrit] wikimedia...civicrm[master]: CRM-21109 only clear caches once on cli script, consolidate ...

2017-09-12 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/377386 )

Change subject: CRM-21109 only clear caches once on cli script, consolidate code
..


CRM-21109 only clear caches once on cli script, consolidate code

This is a combination of the commits in
https://github.com/civicrm/civicrm-core/pull/10943

Bringing this in does not make any actual change for us. However, it makes it 
easier for us
to play with the following options

1) setting cache mode to FALSE on a per process basis.
Currently there are statics to try to ensure that caches are flushed
only once per process, but without this the add to group & remove from
group functions bypass them. From a script
CRM_Core_Config::setPermitCacheFlushMode(FALSE);
would prevent cache flushing in the session for group_contact_cache & acl 
caches until the
script ends or it is retoggled. Also acl caches were not previously subject to 
the statics.
2)We would consider flushing caches by cron rather than during script runtime. 
There
is a setting for that & we could extend to cover acl cache. Flushing by cron
permits (optionally) the use of TRUNCATE - which appears to be faster for 
everyone in the world but us :-)

Change-Id: Ib790939421d3b7ce5d2e258154a8015b8652234f
---
M CRM/ACL/BAO/Cache.php
M CRM/Contact/BAO/Contact.php
M CRM/Contact/BAO/Contact/Utils.php
M CRM/Contact/BAO/GroupContact.php
M CRM/Contact/BAO/GroupContactCache.php
M CRM/Contact/Form/Merge.php
M CRM/Contact/Import/Form/Preview.php
M CRM/Contact/Import/Parser/Contact.php
M CRM/Core/Config.php
M CRM/Dedupe/Merger.php
M bin/cli.class.php
11 files changed, 57 insertions(+), 59 deletions(-)

Approvals:
  jenkins-bot: Verified
  Ejegg: Looks good to me, approved



diff --git a/CRM/ACL/BAO/Cache.php b/CRM/ACL/BAO/Cache.php
index e1e989c..d6f156d 100644
--- a/CRM/ACL/BAO/Cache.php
+++ b/CRM/ACL/BAO/Cache.php
@@ -142,6 +142,9 @@
* Deletes all the cache entries.
*/
   public static function resetCache() {
+if (!CRM_Core_Config::isPermitCacheFlushMode()) {
+  return;
+}
 // reset any static caching
 self::$_cache = NULL;
 
diff --git a/CRM/Contact/BAO/Contact.php b/CRM/Contact/BAO/Contact.php
index 0460b22..f9edbba 100644
--- a/CRM/Contact/BAO/Contact.php
+++ b/CRM/Contact/BAO/Contact.php
@@ -356,9 +356,7 @@
 //add website
 CRM_Core_BAO_Website::create($params['website'], $contact->id, 
$skipDelete);
 
-//get userID from session
-$session = CRM_Core_Session::singleton();
-$userID = $session->get('userID');
+$userID = CRM_Core_Session::singleton()->get('userID');
 // add notes
 if (!empty($params['note'])) {
   if (is_array($params['note'])) {
@@ -432,13 +430,7 @@
   'name'
 );
 
-if (!$config->doNotResetCache) {
-  // Note: doNotResetCache flag is currently set by import contact process 
and merging,
-  // since resetting and
-  // rebuilding cache could be expensive (for many contacts). We might 
come out with better
-  // approach in future.
-  CRM_Contact_BAO_Contact_Utils::clearContactCaches($contact->id);
-}
+CRM_Contact_BAO_Contact_Utils::clearContactCaches();
 
 if ($invokeHooks) {
   if ($isEdit) {
diff --git a/CRM/Contact/BAO/Contact/Utils.php 
b/CRM/Contact/BAO/Contact/Utils.php
index 9cbb44d..2ac9af4 100644
--- a/CRM/Contact/BAO/Contact/Utils.php
+++ b/CRM/Contact/BAO/Contact/Utils.php
@@ -897,18 +897,21 @@
* caches, but are backing off from this with every release. Compromise 
between ease of coding versus
* performance versus being accurate at that very instant
*
-   * @param $contactID
-   *   The contactID that was edited / deleted.
+   * @param bool $isEmptyPrevNextTable
+   *   Should the civicrm_prev_next table be cleared of any contact entries.
+   *   This is currently done from import but not other places and would
+   *   likely affect user experience in unexpected ways. Existing behaviour 
retained
+   *   ... reluctantly.
*/
-  public static function clearContactCaches($contactID = NULL) {
-// clear acl cache if any.
-CRM_ACL_BAO_Cache::resetCache();
-
-if (empty($contactID)) {
-  // also clear prev/next dedupe cache - if no contactID passed in
+  public static function clearContactCaches($isEmptyPrevNextTable = FALSE) {
+if (!CRM_Core_Config::isPermitCacheFlushMode()) {
+  return;
+}
+if ($isEmptyPrevNextTable) {
   CRM_Core_BAO_PrevNextCache::deleteItem();
 }
-
+// clear acl cache if any.
+CRM_ACL_BAO_Cache::resetCache();
 CRM_Contact_BAO_GroupContactCache::opportunisticCacheFlush();
   }
 
diff --git a/CRM/Contact/BAO/GroupContact.php b/CRM/Contact/BAO/GroupContact.php
index 8833d19..73bf59b 100644
--- a/CRM/Contact/BAO/GroupContact.php
+++ b/CRM/Contact/BAO/GroupContact.php
@@ -143,15 +143,7 @@
 list($numContactsAdded, $numContactsNotAdded)
   = self::bulkAddContactsToGroup($contactIds,

[MediaWiki-commits] [Gerrit] wikimedia...civicrm[master]: CRM-21109 only clear caches once on cli script, consolidate ...

2017-09-11 Thread Eileen (Code Review)
Eileen has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/377386 )

Change subject: CRM-21109 only clear caches once on cli script, consolidate code
..

CRM-21109 only clear caches once on cli script, consolidate code

This is a combination of the commits in
https://github.com/civicrm/civicrm-core/pull/10943

Bringing this in does not make any actual change for us. However, it makes it 
easier for us
to play with the following options

1) setting cache mode to FALSE on a per process basis.
Currently there are statics to try to ensure that caches are flushed
only once per process, but without this the add to group & remove from
group functions bypass them. From a script
CRM_Core_Config::setPermitCacheFlushMode(FALSE);
would prevent cache flushing in the session for group_contact_cache & acl 
caches until the
script ends or it is retoggled. Also acl caches were not previously subject to 
the statics.
2)We would consider flushing caches by cron rather than during script runtime. 
There
is a setting for that & we could extend to cover acl cache. Flushing by cron
permits (optionally) the use of TRUNCATE - which appears to be faster for 
everyone in the world but us :-)

Change-Id: Ib790939421d3b7ce5d2e258154a8015b8652234f
---
M CRM/ACL/BAO/Cache.php
M CRM/Contact/BAO/Contact.php
M CRM/Contact/BAO/Contact/Utils.php
M CRM/Contact/BAO/GroupContact.php
M CRM/Contact/BAO/GroupContactCache.php
M CRM/Contact/Form/Merge.php
M CRM/Contact/Import/Form/Preview.php
M CRM/Contact/Import/Parser/Contact.php
M CRM/Core/Config.php
M CRM/Dedupe/Merger.php
M bin/cli.class.php
11 files changed, 57 insertions(+), 59 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/crm/civicrm 
refs/changes/86/377386/1

diff --git a/CRM/ACL/BAO/Cache.php b/CRM/ACL/BAO/Cache.php
index e1e989c..d6f156d 100644
--- a/CRM/ACL/BAO/Cache.php
+++ b/CRM/ACL/BAO/Cache.php
@@ -142,6 +142,9 @@
* Deletes all the cache entries.
*/
   public static function resetCache() {
+if (!CRM_Core_Config::isPermitCacheFlushMode()) {
+  return;
+}
 // reset any static caching
 self::$_cache = NULL;
 
diff --git a/CRM/Contact/BAO/Contact.php b/CRM/Contact/BAO/Contact.php
index 0460b22..f9edbba 100644
--- a/CRM/Contact/BAO/Contact.php
+++ b/CRM/Contact/BAO/Contact.php
@@ -356,9 +356,7 @@
 //add website
 CRM_Core_BAO_Website::create($params['website'], $contact->id, 
$skipDelete);
 
-//get userID from session
-$session = CRM_Core_Session::singleton();
-$userID = $session->get('userID');
+$userID = CRM_Core_Session::singleton()->get('userID');
 // add notes
 if (!empty($params['note'])) {
   if (is_array($params['note'])) {
@@ -432,13 +430,7 @@
   'name'
 );
 
-if (!$config->doNotResetCache) {
-  // Note: doNotResetCache flag is currently set by import contact process 
and merging,
-  // since resetting and
-  // rebuilding cache could be expensive (for many contacts). We might 
come out with better
-  // approach in future.
-  CRM_Contact_BAO_Contact_Utils::clearContactCaches($contact->id);
-}
+CRM_Contact_BAO_Contact_Utils::clearContactCaches();
 
 if ($invokeHooks) {
   if ($isEdit) {
diff --git a/CRM/Contact/BAO/Contact/Utils.php 
b/CRM/Contact/BAO/Contact/Utils.php
index 9cbb44d..2ac9af4 100644
--- a/CRM/Contact/BAO/Contact/Utils.php
+++ b/CRM/Contact/BAO/Contact/Utils.php
@@ -897,18 +897,21 @@
* caches, but are backing off from this with every release. Compromise 
between ease of coding versus
* performance versus being accurate at that very instant
*
-   * @param $contactID
-   *   The contactID that was edited / deleted.
+   * @param bool $isEmptyPrevNextTable
+   *   Should the civicrm_prev_next table be cleared of any contact entries.
+   *   This is currently done from import but not other places and would
+   *   likely affect user experience in unexpected ways. Existing behaviour 
retained
+   *   ... reluctantly.
*/
-  public static function clearContactCaches($contactID = NULL) {
-// clear acl cache if any.
-CRM_ACL_BAO_Cache::resetCache();
-
-if (empty($contactID)) {
-  // also clear prev/next dedupe cache - if no contactID passed in
+  public static function clearContactCaches($isEmptyPrevNextTable = FALSE) {
+if (!CRM_Core_Config::isPermitCacheFlushMode()) {
+  return;
+}
+if ($isEmptyPrevNextTable) {
   CRM_Core_BAO_PrevNextCache::deleteItem();
 }
-
+// clear acl cache if any.
+CRM_ACL_BAO_Cache::resetCache();
 CRM_Contact_BAO_GroupContactCache::opportunisticCacheFlush();
   }
 
diff --git a/CRM/Contact/BAO/GroupContact.php b/CRM/Contact/BAO/GroupContact.php
index 8833d19..73bf59b 100644
--- a/CRM/Contact/BAO/GroupContact.php
+++ b/CRM/Contact/BAO/GroupContact.php
@@ -143,15 +143,7 @@
 list($numContactsAdded, $numContactsNotAdded)
   = self::bulkAddContactsT