CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • civicrm_group_contact_cache - extra join?
Pages: [1]

Author Topic: civicrm_group_contact_cache - extra join?  (Read 1017 times)

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
civicrm_group_contact_cache - extra join?
May 09, 2011, 09:02:53 pm
Hi,

This is all over our slow query log. I don't think the query itself is the reason but looking at it I can't for the life or me see why the join to the contact table is required here

DELETE     g
FROM       civicrm_group_contact_cache g
INNER JOIN civicrm_contact c ON c.id = g.contact_id
WHERE      g.group_id IN (
    SELECT id
    FROM   civicrm_group
    WHERE  TIMESTAMPDIFF(MINUTE, cache_date, $now) >= $smartGroupCacheTimeout   
)
";
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: civicrm_group_contact_cache - extra join?
May 09, 2011, 09:58:08 pm
that query looks mighty odd. can u give this one a try instead:

Code: [Select]
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                                                             
« Last Edit: May 10, 2011, 07:31:30 pm by Donald Lobo »
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: civicrm_group_contact_cache - extra join?
May 09, 2011, 10:00:02 pm
Will try - nb  query is in

CRM_Contact_BAO_GroupContactCache::store
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: civicrm_group_contact_cache - extra join?
May 10, 2011, 06:03:29 pm
I think you mean this

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   

Can you update your post so no-one ever copies it & uses it - delete from cache table not groups table   
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: civicrm_group_contact_cache - extra join?
May 10, 2011, 06:21:52 pm
Also is seems to me that when $config->smartGroupCacheTimeout is not set then the whole query should be

Code: [Select]
DELETE     g
FROM       civicrm_group_contact_cache g

(Or Truncate civicrm_group_contact_cache)

Current code sets   $smartGroupCacheTimeout  to null & runs the complex query below rather than running a different query if it isn't set

Code: [Select]
        $smartGroupCacheTimeout =
            isset( $config->smartGroupCacheTimeout ) && is_numeric(  $config->smartGroupCacheTimeout ) ? $config->smartGroupCacheTimeout : 0;

        if ( ! isset( $groupID ) ) {
            $query = "
DELETE     g
FROM       civicrm_group_contact_cache g
INNER JOIN civicrm_contact c ON c.id = g.contact_id
WHERE      g.group_id IN (
    SELECT id
    FROM   civicrm_group
    WHERE  TIMESTAMPDIFF(MINUTE, cache_date, $now) >= $smartGroupCacheTimeout   
)
";
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • civicrm_group_contact_cache - extra join?

This forum was archived on 2017-11-26.