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 pledge reports #11875

Merged
merged 1 commit into from
Mar 26, 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
13 changes: 3 additions & 10 deletions CRM/Report/Form/Pledge/Detail.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,16 +286,9 @@ public function from() {
";
}

$this->addPhoneFromClause();
$this->addAddressFromClause();
// include email field 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->joinPhoneFromContact();
$this->joinAddressFromContact();
$this->joinEmailFromContact();
}

/**
Expand Down
26 changes: 2 additions & 24 deletions CRM/Report/Form/Pledge/Pbnp.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,14 +230,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'] = CRM_Utils_Array::value('type', $field);
$this->_columnHeaders["{$tableName}_{$fieldName}"]['title'] = CRM_Utils_Array::value('title', $field);
Expand Down Expand Up @@ -279,23 +271,9 @@ public function from() {
ON ({$this->_aliases['civicrm_pledge']}.id =
{$this->_aliases['civicrm_pledge_payment']}.pledge_id AND {$this->_aliases['civicrm_pledge_payment']}.status_id = {$pendingStatus} ) ";

// include address field 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";
}
$this->joinAddressFromContact();
$this->joinEmailFromContact();

// include email field 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";
}
}

public function groupBy() {
Expand Down
21 changes: 2 additions & 19 deletions CRM/Report/Form/Pledge/Summary.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ class CRM_Report_Form_Pledge_Summary extends CRM_Report_Form {
protected $_totalPaid = FALSE;
protected $_customGroupExtends = array('Pledge', 'Individual');
protected $_customGroupGroupBy = TRUE;
protected $_addressField = FALSE;
protected $_emailField = FALSE;

/**
* This report has not been optimised for group filtering.
Expand Down Expand Up @@ -216,23 +214,8 @@ public function from() {
{$this->_aliases['civicrm_pledge']}.contact_id )
{$this->_aclFrom} ";

// include address field 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 field 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();

if (!empty($this->_params['fields']['total_paid'])) {
$this->_from .= "
Expand Down
28 changes: 4 additions & 24 deletions CRM/Report/Form/Walklist/Walklist.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@
* @copyright CiviCRM LLC (c) 2004-2018
*/
class CRM_Report_Form_Walklist_Walklist extends CRM_Report_Form {
protected $_addressField = FALSE;

protected $_emailField = FALSE;

protected $_phoneField = FALSE;

protected $_summary = NULL;

Expand Down Expand Up @@ -149,6 +144,7 @@ public function preProcess() {
}

public function select() {
// @todo remove this function & use parent.
$select = array();

$this->_columnHeaders = array();
Expand All @@ -157,15 +153,6 @@ public function select() {
if (!empty($field['required']) ||
!empty($this->_params['fields'][$fieldName])
) {
if ($tableName == 'civicrm_address') {
$this->_addressField = TRUE;
}
elseif ($tableName == 'civicrm_email') {
$this->_emailField = TRUE;
}
elseif ($tableName == 'civicrm_phone') {
$this->_phoneField = TRUE;
}

$select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
$this->_columnHeaders["{$tableName}_{$fieldName}"]['title'] = $field['title'];
Expand All @@ -183,17 +170,10 @@ public function from() {
$this->_from = "
FROM civicrm_contact {$this->_aliases['civicrm_contact']} {$this->_aclFrom}
";
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";
}

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";
}

if ($this->_phoneField) {
$this->_from .= "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\n";
}
$this->joinAddressFromContact();
$this->joinPhoneFromContact();
$this->joinEmailFromContact();
}

public function where() {
Expand Down