Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRM-21677 reduce unnecessary joins in reports #11889

Merged
merged 1 commit into from
Mar 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions CRM/Report/Form/Contact/CurrentEmployer.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,17 +252,11 @@ public function from() {
LEFT JOIN civicrm_relationship {$this->_aliases['civicrm_relationship']}
ON ( {$this->_aliases['civicrm_relationship']}.contact_id_a={$this->_aliases['civicrm_contact']}.id
AND {$this->_aliases['civicrm_relationship']}.contact_id_b={$this->_aliases['civicrm_contact']}.employer_id
AND {$this->_aliases['civicrm_relationship']}.relationship_type_id={$relType})
LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']}
ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_address']}.contact_id
AND {$this->_aliases['civicrm_address']}.is_primary = 1 )

LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone']}
ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_phone']}.contact_id
AND {$this->_aliases['civicrm_phone']}.is_primary = 1)
LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']}
ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_email']}.contact_id
AND {$this->_aliases['civicrm_email']}.is_primary = 1) ";
AND {$this->_aliases['civicrm_relationship']}.relationship_type_id={$relType}) ";

$this->joinAddressFromContact();
$this->joinPhoneFromContact();
$this->joinEmailFromContact();
}

public function where() {
Expand Down
3 changes: 0 additions & 3 deletions CRM/Report/Form/Contribute/Bookkeeping.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@
* @copyright CiviCRM LLC (c) 2004-2018
*/
class CRM_Report_Form_Contribute_Bookkeeping extends CRM_Report_Form {
protected $_addressField = FALSE;

protected $_emailField = FALSE;

protected $_summary = NULL;

Expand Down
13 changes: 4 additions & 9 deletions CRM/Report/Form/Event/ParticipantListCount.php
Original file line number Diff line number Diff line change
Expand Up @@ -462,17 +462,12 @@ public function from() {
{$this->_aclFrom}
LEFT JOIN civicrm_contact {$this->_aliases['civicrm_employer']}
ON ({$this->_aliases['civicrm_employer']}.id = {$this->_aliases['civicrm_contact']}.employer_id )
LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']}
ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_address']}.contact_id AND
{$this->_aliases['civicrm_address']}.is_primary = 1
LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']}
ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_email']}.contact_id AND
{$this->_aliases['civicrm_email']}.is_primary = 1)
LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone']}
ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_phone']}.contact_id AND
{$this->_aliases['civicrm_phone']}.is_primary = 1
LEFT JOIN civicrm_line_item {$this->_aliases['civicrm_line_item']}
ON {$this->_aliases['civicrm_line_item']}.entity_table = 'civicrm_participant' AND {$this->_aliases['civicrm_participant']}.id ={$this->_aliases['civicrm_line_item']}.entity_id";

$this->joinAddressFromContact();
$this->joinPhoneFromContact();
$this->joinEmailFromContact();
}

public function storeWhereHavingClauseArray() {
Expand Down
14 changes: 5 additions & 9 deletions CRM/Report/Form/Event/ParticipantListing.php
Original file line number Diff line number Diff line change
Expand Up @@ -513,16 +513,12 @@ public function from() {
LEFT JOIN civicrm_contact {$this->_aliases['civicrm_contact']}
ON ({$this->_aliases['civicrm_participant']}.contact_id = {$this->_aliases['civicrm_contact']}.id )
{$this->_aclFrom}
LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']}
ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_address']}.contact_id AND
{$this->_aliases['civicrm_address']}.is_primary = 1
LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']}
ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_email']}.contact_id AND
{$this->_aliases['civicrm_email']}.is_primary = 1)
LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone']}
ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_phone']}.contact_id AND
{$this->_aliases['civicrm_phone']}.is_primary = 1
";

$this->joinAddressFromContact();
$this->joinPhoneFromContact();
$this->joinEmailFromContact();

if ($this->_contribField) {
$this->_from .= "
LEFT JOIN civicrm_participant_payment pp
Expand Down
20 changes: 3 additions & 17 deletions CRM/Report/Form/Membership/Summary.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ public function preProcess() {
* Generate select clause.
*/
public function select() {
// @todo remove this in favour of just using parent.
$select = array();
$this->_columnHeaders = array();
foreach ($this->_columns as $tableName => $table) {
Expand All @@ -156,14 +157,6 @@ public function select() {
if (!empty($field['required']) ||
!empty($this->_params['fields'][$fieldName])
) {
// to include optional columns address and email, only if checked
if ($tableName == 'civicrm_address') {
$this->_addressField = TRUE;
$this->_emailField = TRUE;
}
elseif ($tableName == 'civicrm_email') {
$this->_emailField = TRUE;
}
$select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
$this->_columnHeaders["{$tableName}_{$fieldName}"]['type'] = $field['type'];
$this->_columnHeaders["{$tableName}_{$fieldName}"]['title'] = $field['title'];
Expand All @@ -189,15 +182,8 @@ public function from() {
LEFT JOIN civicrm_contribution {$this->_aliases['civicrm_contribution']}
ON {$this->_aliases['civicrm_membership']}.contact_id = {$this->_aliases['civicrm_contribution']}.contact_id
";
// Include address table if address column is to be included.
if ($this->_addressField) {
$this->_from .= "LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']} ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_address']}.contact_id AND {$this->_aliases['civicrm_address']}.is_primary = 1\n";
}

// Include email table if email column is to be included.
if ($this->_emailField) {
$this->_from .= "LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']} ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_email']}.contact_id AND {$this->_aliases['civicrm_email']}.is_primary = 1\n";
}
$this->joinAddressFromContact();
$this->joinEmailFromContact();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eileenmcnaughton I don't see any email/address columns in Membership Summary report

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm - in construct I see

      'civicrm_email' => array(
        'dao' => 'CRM_Core_DAO_Email',
        'fields' => array('email' => NULL),
        'grouping' => 'contact-fields',
      ),

which seems kinda weird!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same in memberDetail too TBH - what do you think? I'm inclined to merge this as more standardised & safer than stripping out the join. We could also add more email fields/filters - but I'm wary of growing the scope for something neither of us are vested in


/**
Expand Down