From: Patrick Figel Date: Tue, 29 Jan 2019 21:10:12 +0000 (+0100) Subject: CRM/Contribute - Add query optimization for creditnote_id X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=6bceeca1974831bd4630bf2c5c024068f3b0300f;p=civicrm-core.git CRM/Contribute - Add query optimization for creditnote_id This adds a minor query optimization to createCreditNoteId() that should significantly improve performance when contributions are cancelled or refunded in environments with many contributions. --- diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 2567ede134..f2db42dc3f 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -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 {