<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.3 |
+ | CiviCRM version 4.5 |
+--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013 |
+ | Copyright CiviCRM LLC (c) 2004-2014 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
/**
*
* @package CRM
- * @copyright CiviCRM LLC (c) 2004-2013
+ * @copyright CiviCRM LLC (c) 2004-2014
* $Id$
*
*/
if (!empty($refreshGroupIDs)) {
$refreshGroupIDString = CRM_Core_DAO::escapeString(implode(', ', $refreshGroupIDs));
- $time = CRM_Utils_Date::getUTCTime($smartGroupCacheTimeout * 60);
+ $time = CRM_Utils_Date::getUTCTime(self::smartGroupCacheTimeout() * 60);
$query = "
UPDATE civicrm_group g
SET g.refresh_date = $time
CRM_Core_DAO::executeQuery($sql);
}
+ /**
+ * Removes all the cache entries pertaining to a specific group
+ * If no groupID is passed in, removes cache entries for all groups
+ * Has an optimization to bypass repeated invocations of this function.
+ * Note that this function is an advisory, i.e. the removal respects the
+ * cache date, i.e. the removal is not done if the group was recently
+ * loaded into the cache.
+ *
+ * @param $groupID int the groupID to delete cache entries, NULL for all groups
+ * @param $onceOnly boolean run the function exactly once for all groups.
+ *
+ * @public
+ * @return void
+ * @static
+ */
static function remove($groupID = NULL, $onceOnly = TRUE) {
static $invoked = FALSE;
// done
// we allow hidden groups here since we dont know if the caller wants to evaluate an
// hidden group
- if (!$force && !self::shouldGroupBeRefreshed($groupID, FALSE, TRUE)) {
+ if (!$force && !self::shouldGroupBeRefreshed($groupID, TRUE)) {
$lock->release();
return;
}
$groupIDs = array($groupID);
self::remove($groupIDs);
-
$processed = FALSE;
+ $tempTable = 'civicrm_temp_group_contact_cache' . rand(0,2000);
foreach (array($sql, $sqlB) as $selectSql) {
if (!$selectSql) {
continue;
}
- $insertSql = "INSERT IGNORE INTO civicrm_group_contact_cache (group_id,contact_id) ($selectSql);";
+ $insertSql = "CREATE TEMPORARY TABLE $tempTable ($selectSql);";
$processed = TRUE;
$result = CRM_Core_DAO::executeQuery($insertSql);
+ CRM_Core_DAO::executeQuery(
+ "INSERT IGNORE INTO civicrm_group_contact_cache (contact_id, group_id)
+ SELECT DISTINCT $idName, group_id FROM $tempTable
+ ");
+ CRM_Core_DAO::executeQuery(" DROP TABLE $tempTable");
}
+
self::updateCacheTime($groupIDs, $processed);
if ($group->children) {