Created
September 3, 2019 15:19
-
-
Save MegaphoneJon/59089c1e155645a438af41051bca7ce7 to your computer and use it in GitHub Desktop.
CiviCRM Smart group profiling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/php | |
<?php | |
// Use this code to see how long it takes to generate all of your smart groups to find slow ones. | |
eval(`cv php:boot`); | |
//Force a refresh of the cache | |
$sql = 'UPDATE civicrm_group SET cache_date = NULL, refresh_date = NULL'; | |
CRM_Core_DAO::executeQuery($sql); | |
// Get a list of smart group IDs. | |
$smartGroups = civicrm_api3('Group', 'get', [ | |
'return' => ["id", "title"], | |
'options' => ['limit' => 0], | |
'saved_search_id.id' => ['IS NOT NULL' => 1], | |
'is_active' => 1, | |
'is_hidden' => 0, | |
])['values']; | |
//place this before any script you want to calculate time | |
foreach ($smartGroups as $group) { | |
$time_start = microtime(true); | |
echo "{$group['title']} ({$group['id']}): "; | |
CRM_Contact_BAO_GroupContactCache::loadAll($group['id']); | |
$time_end = microtime(true); | |
$executionTime = ($time_end - $time_start); | |
echo "$executionTime seconds\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment