From 7a25e5410b720e6d098c6d3a5a9d202c5e723945 Mon Sep 17 00:00:00 2001 From: Rich Lott / Artful Robot Date: Wed, 6 Sep 2023 09:58:15 +0100 Subject: [PATCH] Move cache_fill_took to float/double; only update when there's a good value --- CRM/Contact/BAO/GroupContactCache.php | 8 +++++--- CRM/Upgrade/Incremental/php/FiveSixtySix.php | 4 +++- xml/schema/Contact/Group.xml | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/CRM/Contact/BAO/GroupContactCache.php b/CRM/Contact/BAO/GroupContactCache.php index 29f3c27dd0..2400867d81 100644 --- a/CRM/Contact/BAO/GroupContactCache.php +++ b/CRM/Contact/BAO/GroupContactCache.php @@ -167,12 +167,15 @@ AND ( */ protected static function updateCacheTime($groupID, $processed, ?float $startTime = NULL) { // only update cache entry if we had any values - $took = $now = 'null'; + $now = 'null'; + $setCacheFillTook = ''; if ($processed) { // also update the group with cache date information $now = date('YmdHis'); if ($startTime) { + // If we can calculate how long this took, we update the cache_fill_took column. $took = microtime(TRUE) - $startTime; + $setCacheFillTook = ", cache_fill_took = $took"; $maxTime = CRM_Utils_Constant::value('CIVICRM_SLOW_SMART_GROUP_SECONDS'); if ($maxTime && $took > $maxTime) { Civi::log()->warning( @@ -187,8 +190,7 @@ AND ( $groupIDs = implode(',', $groupID); $sql = " UPDATE civicrm_group -SET cache_date = $now, - cache_fill_took = $took +SET cache_date = $now$setCacheFillTook WHERE id IN ( $groupIDs ) "; CRM_Core_DAO::executeQuery($sql); diff --git a/CRM/Upgrade/Incremental/php/FiveSixtySix.php b/CRM/Upgrade/Incremental/php/FiveSixtySix.php index e6af31416e..8b940882ab 100644 --- a/CRM/Upgrade/Incremental/php/FiveSixtySix.php +++ b/CRM/Upgrade/Incremental/php/FiveSixtySix.php @@ -48,7 +48,9 @@ class CRM_Upgrade_Incremental_php_FiveSixtySix extends CRM_Upgrade_Incremental_B $this->addTask('Update afform tab names', 'updateAfformTabs'); $this->addTask('Add in Client Removed Activity Type', 'addCaseClientRemovedActivity'); $this->addTask('Update quicksearch options to v4 format', 'updateQuicksearchOptions'); - $this->addTask('Add cache_fill_took column to Group table', 'addColumn', 'civicrm_group', 'cache_fill_took', "DECIMAL(10,3) COMMENT 'Seconds taken to fill smart group cache'", FALSE); + $this->addTask('Add cache_fill_took column to Group table', 'addColumn', 'civicrm_group', 'cache_fill_took', + 'DOUBLE DEFAULT NULL COMMENT "Seconds taken to fill smart group cache, not always related to cache_date"', + FALSE); } /** diff --git a/xml/schema/Contact/Group.xml b/xml/schema/Contact/Group.xml index 275a7eef6e..dc60e19a1b 100644 --- a/xml/schema/Contact/Group.xml +++ b/xml/schema/Contact/Group.xml @@ -178,7 +178,7 @@ cache_fill_took - decimal + float Seconds taken by last cache fill Seconds taken to fill smart group cache false -- 2.25.1