Uploaded image for project: 'CiviCRM'
  1. CiviCRM
  2. CRM-4421

Advanced search: all group_contact records being retrieved but not used

    Details

    • Type: Bug
    • Status: Done/Fixed
    • Priority: Minor
    • Resolution: Fixed/Completed
    • Affects Version/s: 2.2.0
    • Fix Version/s: 2.2.3
    • Component/s: CiviCRM Search
    • Labels:
      None

      Description

      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 value which is non-empty and not equal to any of the valid values ('-' in my case).
      • I suggest someone looks at the condition "if ( empty( $result->status ) )". It's not clear to me that this is a sufficient test. I didn't change that condition because I didn't understand the side-effects. But I expect that this is the condition which needs to be strengthened.

        Attachments

          Activity

            People

            • Assignee:
              shailesh Shailesh Lende
              Reporter:
              ken Ken West
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: