CRM-18109 towards removal of unindexed queries
authoreileenmcnaugton <eileen@fuzion.co.nz>
Fri, 19 Feb 2016 06:13:19 +0000 (19:13 +1300)
committerJKingsnorth <john@johnkingsnorth.co.uk>
Thu, 25 Feb 2016 16:14:05 +0000 (16:14 +0000)
Signed-off-by: JKingsnorth <john@johnkingsnorth.co.uk>
CRM/Contact/BAO/GroupContactCache.php

index ba013e276dedb5c1ecd4d549c1ea9ebb8f59cd77..2d3d087b65e5ba952a633fc020506df5cc0766d1 100644 (file)
@@ -334,24 +334,27 @@ SET    cache_date = null,
 ";
       }
       else {
+
         $query = "
 DELETE     gc
 FROM       civicrm_group_contact_cache gc
 INNER JOIN civicrm_group g ON g.id = gc.group_id
-WHERE      TIMESTAMPDIFF(MINUTE, g.cache_date, $now) >= $smartGroupCacheTimeout
+WHERE      g.cache_date >= %1
 ";
         $update = "
 UPDATE civicrm_group g
 SET    cache_date = null,
        refresh_date = null
-WHERE  TIMESTAMPDIFF(MINUTE, cache_date, $now) >= $smartGroupCacheTimeout
+WHERE  g.cache_date >= %1
 ";
         $refresh = "
 UPDATE civicrm_group g
 SET    refresh_date = $refreshTime
-WHERE  TIMESTAMPDIFF(MINUTE, cache_date, $now) < $smartGroupCacheTimeout
+WHERE  g.cache_date < %1
 AND    refresh_date IS NULL
 ";
+        $cacheTime = date('Y-m-d H-i-s', strtotime("- $smartGroupCacheTimeout minutes"));
+        $params = array(1 => array($cacheTime, 'String'));
       }
     }
     elseif (is_array($groupID)) {