Eileen has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/327054 )

Change subject: CRM-19752 Fix slow query on contribution dash.
......................................................................

CRM-19752 Fix slow query on contribution dash.

The ACL where clause & from slows down this query :-(

Bug: T152936
Change-Id: Ic510ed888342ee3cf294ba03574464e8bb47c617
---
M CRM/Contribute/BAO/Contribution.php
1 file changed, 13 insertions(+), 8 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/crm/civicrm 
refs/changes/54/327054/1

diff --git a/CRM/Contribute/BAO/Contribution.php 
b/CRM/Contribute/BAO/Contribution.php
index a8223d8..9afb4be 100644
--- a/CRM/Contribute/BAO/Contribution.php
+++ b/CRM/Contribute/BAO/Contribution.php
@@ -915,13 +915,18 @@
     if ($endDate) {
       $where[] = "receive_date <= '" . CRM_Utils_Type::escape($endDate, 
'Timestamp') . "'";
     }
-    
CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes);
-    if ($financialTypes) {
-      $where[] = "c.financial_type_id IN (" . implode(',', 
array_keys($financialTypes)) . ")";
-      $where[] = "i.financial_type_id IN (" . implode(',', 
array_keys($financialTypes)) . ")";
-    }
-    else {
-      $where[] = "c.financial_type_id IN (0)";
+    $financialTypeACLJoin = '';
+    if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus()) {
+      $financialTypeACLJoin = " LEFT JOIN civicrm_line_item i ON 
(i.contribution_id = c.id AND i.entity_table = 'civicrm_contribution') ";
+      $financialTypes = CRM_Contribute_PseudoConstant::financialType();
+      
CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes);
+      if ($financialTypes) {
+        $where[] = "c.financial_type_id IN (" . implode(',', 
array_keys($financialTypes)) . ")";
+        $where[] = "i.financial_type_id IN (" . implode(',', 
array_keys($financialTypes)) . ")";
+      }
+      else {
+        $where[] = "c.financial_type_id IN (0)";
+      }
     }
 
     $whereCond = implode(' AND ', $where);
@@ -932,7 +937,7 @@
             currency
       FROM  civicrm_contribution c
 INNER JOIN  civicrm_contact contact ON ( contact.id = c.contact_id )
-LEFT JOIN  civicrm_line_item i ON ( i.contribution_id = c.id AND 
i.entity_table = 'civicrm_contribution' )
+     $financialTypeACLJoin
      WHERE  $whereCond
        AND  ( is_test = 0 OR is_test IS NULL )
        AND  contact.is_deleted = 0

-- 
To view, visit https://gerrit.wikimedia.org/r/327054
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic510ed888342ee3cf294ba03574464e8bb47c617
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/crm/civicrm
Gerrit-Branch: master
Gerrit-Owner: Eileen <emcnaugh...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to