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) »
  • Support »
  • Using CiviCRM »
  • Using Profiles (Moderator: Dave Greenberg) »
  • Defect: all group_contacts being returned but not used
Pages: [1]

Author Topic: Defect: all group_contacts being returned but not used  (Read 1030 times)

ken

  • I live on this forum
  • *****
  • Posts: 916
  • Karma: 53
    • City Bible Forum
  • CiviCRM version: 4.6.3
  • CMS version: Drupal 7.36
  • MySQL version: 5.5.41
  • PHP version: 5.3.10
Defect: all group_contacts being returned but not used
April 26, 2009, 02:02:24 am
I've found a case where Civi performs an unnecessary and expensive(?) query. I have a fix.

To reproduce: With CiviCRM 2.2.0, invoke Advanced Search, using a profile in the Search View, and using criteria that do not include groups.

The problem: At line 591 in CRM/Contact/Selector.php, a call is made to CRM_Core_DAO::commonRetrieve() that results in the query "SELECT * FROM civicrm_group_contact" being made. On my server this leads to an "out-of-memory" error, which I could fix by raising limits, but I'd prefer to see fixed by removing the issue.

  • The problem occurs when $result->status is empty, no group is selected in the search criteria, and there is no contact_id in $row. Under these conditions, all group_contacts are retrieved, and the first one is placed in $gcDefaults.
  • Not only is the first one most probably the wrong one, but it's an unnecessary overhead to perform this query
  • In my fix, I test whether the group_id and contact_id are both non-empty before making the call. Otherwise I set $row['status'] to a non-empty value.

The fix:

Code: [Select]
--- administrator/components/com_civicrm/civicrm/CRM/Contact/Selector.php 2009-03-14 18:52:17.000000000 +1100
+++ local/php/CRM/Contact/Selector.php 2009-04-26 17:49:26.000000000 +1000
@@ -582,24 +582,28 @@
             if ( $output != CRM_Core_Selector_Controller::EXPORT ||
                  $context == 'smog' ) {
                 if ( empty( $result->status ) ) {
                     //check explicitly added contact to a Smart Group.
                     $groupID  = CRM_Utils_Array::key( '1', $this->_formValues['group'] ); 
                     $gcParams = array('contact_id' => CRM_Utils_Array::value( 'contact_id', $row ),
                                       'group_id'   => $groupID,
                                       );
+                    if ( empty( $gcParams['contact_id'] ) || empty( $gcParams['group_id'] ) ) {
+                        $row['status'] = '-';
+                    } else {
                     $gcDefaults = array( );
                     CRM_Core_DAO::commonRetrieve( 'CRM_Contact_DAO_GroupContact', $gcParams, $gcDefaults );
                     
                     if ( empty( $gcDefaults ) ) {
                         $row['status'] = ts('Smart');
                     } else {
                         $row['status'] = $gc[$gcDefaults['status']];
                     }
+                    }
                 } else {
                     $row['status'] = $gc[$result->status];
                 }
             }
             
             if ( $output != CRM_Core_Selector_Controller::EXPORT ) {
                 $row['checkbox'] = CRM_Core_Form::CB_PREFIX . $result->contact_id;
 

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: Defect: all group_contacts being returned but not used
April 26, 2009, 07:26:10 am

great catch. Wanna file an issue for this and we'll fix in 2.2.3

thanx

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

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Profiles (Moderator: Dave Greenberg) »
  • Defect: all group_contacts being returned but not used

This forum was archived on 2017-11-26.