CRM/Contribute - Add query optimization for creditnote_id
authorPatrick Figel <pfigel@greenpeace.org>
Tue, 29 Jan 2019 21:10:12 +0000 (22:10 +0100)
committerPatrick Figel <pfigel@greenpeace.org>
Tue, 29 Jan 2019 21:10:12 +0000 (22:10 +0100)
This adds a minor query optimization to createCreditNoteId() that
should significantly improve performance when contributions are
cancelled or refunded in environments with many contributions.

CRM/Contribute/BAO/Contribution.php

index 2567ede134f6119e6801aa43f4ad386773d8f229..f2db42dc3f919efaa8b0a093a48d36ce248f6dae 100644 (file)
@@ -4743,7 +4743,7 @@ WHERE ft.is_payment = 1
   public static function createCreditNoteId() {
     $prefixValue = Civi::settings()->get('contribution_invoice_settings');
 
-    $creditNoteNum = CRM_Core_DAO::singleValueQuery("SELECT count(creditnote_id) as creditnote_number FROM civicrm_contribution");
+    $creditNoteNum = CRM_Core_DAO::singleValueQuery("SELECT count(creditnote_id) as creditnote_number FROM civicrm_contribution WHERE creditnote_id IS NOT NULL");
     $creditNoteId = NULL;
 
     do {