From cee6abcb5782f510a1af8dbbdd56f0c8a5488a2b Mon Sep 17 00:00:00 2001 From: barredterra <14891507+barredterra@users.noreply.github.com> Date: Wed, 30 Oct 2024 01:30:39 +0100 Subject: [PATCH 1/2] perf: set a hard limit on query results (cherry picked from commit 90ab122ef9ba010572a017d6c571b22e3c29bf17) # Conflicts: # banking/klarna_kosma_integration/doctype/bank_reconciliation_tool_beta/bank_reconciliation_tool_beta.py --- .../bank_reconciliation_tool_beta.py | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/banking/klarna_kosma_integration/doctype/bank_reconciliation_tool_beta/bank_reconciliation_tool_beta.py b/banking/klarna_kosma_integration/doctype/bank_reconciliation_tool_beta/bank_reconciliation_tool_beta.py index 9f4f1ae6..e9703a07 100644 --- a/banking/klarna_kosma_integration/doctype/bank_reconciliation_tool_beta/bank_reconciliation_tool_beta.py +++ b/banking/klarna_kosma_integration/doctype/bank_reconciliation_tool_beta/bank_reconciliation_tool_beta.py @@ -19,6 +19,9 @@ from erpnext.accounts.utils import get_account_currency +MAX_QUERY_RESULTS = 150 + + class BankReconciliationToolBeta(Document): pass @@ -660,6 +663,7 @@ def get_bt_matching_query(exact_match, transaction, exact_party_match): .where(bt.bank_account == transaction.bank_account) .where(amount_condition) .where(bt.docstatus == 1) + .limit(MAX_QUERY_RESULTS) ) if exact_party_match: @@ -705,7 +709,12 @@ def get_ld_matching_query(bank_account, exact_match, transaction): ) .where(loan_disbursement.docstatus == 1) .where(loan_disbursement.clearance_date.isnull()) +<<<<<<< HEAD .where(loan_disbursement.disbursement_account == bank_account) +======= + .where(loan_disbursement.disbursement_account == common_filters.bank_account) + .limit(MAX_QUERY_RESULTS) +>>>>>>> 90ab122 (perf: set a hard limit on query results) ) if exact_match: @@ -753,7 +762,12 @@ def get_lr_matching_query(bank_account, exact_match, transaction): ) .where(loan_repayment.docstatus == 1) .where(loan_repayment.clearance_date.isnull()) +<<<<<<< HEAD .where(loan_repayment.payment_account == bank_account) +======= + .where(loan_repayment.payment_account == common_filters.bank_account) + .limit(MAX_QUERY_RESULTS) +>>>>>>> 90ab122 (perf: set a hard limit on query results) ) if frappe.db.has_column("Loan Repayment", "repay_from_salary"): @@ -830,6 +844,7 @@ def get_pe_matching_query( .where(amount_condition) .where(filter_by_date) .orderby(pe.reference_date if cint(filter_by_reference_date) else pe.posting_date) + .limit(MAX_QUERY_RESULTS) ) if frappe.flags.auto_reconcile_vouchers: @@ -898,6 +913,7 @@ def get_je_matching_query( .where(je.docstatus == 1) .where(filter_by_date) .orderby(je.cheque_date if cint(filter_by_reference_date) else je.posting_date) + .limit(MAX_QUERY_RESULTS) ) if frappe.flags.auto_reconcile_vouchers: @@ -947,6 +963,7 @@ def get_si_matching_query(exact_match, exact_party_match, currency): .where(sip.account == Parameter("%(bank_account)s")) .where(amount_condition) .where(si.currency == currency) + .limit(MAX_QUERY_RESULTS) ) if exact_party_match: @@ -989,6 +1006,7 @@ def get_unpaid_si_matching_query( .where(sales_invoice.company == company) # because we do not have bank account check .where(sales_invoice.outstanding_amount != 0.0) .where(sales_invoice.currency == currency) + .limit(MAX_QUERY_RESULTS) ) if include_only_returns: @@ -1046,6 +1064,7 @@ def get_pi_matching_query(exact_match, exact_party_match, currency): .where(purchase_invoice.cash_bank_account == Parameter("%(bank_account)s")) .where(amount_condition) .where(purchase_invoice.currency == currency) + .limit(MAX_QUERY_RESULTS) ) if exact_party_match: @@ -1091,6 +1110,7 @@ def get_unpaid_pi_matching_query( .where(purchase_invoice.outstanding_amount != 0.0) .where(purchase_invoice.is_paid == 0) .where(purchase_invoice.currency == currency) + .limit(MAX_QUERY_RESULTS) ) if include_only_returns: @@ -1143,6 +1163,7 @@ def get_unpaid_ec_matching_query(exact_match, exact_party_match, currency, compa .where(expense_claim.company == company) .where(outstanding_amount > 0.0) .where(expense_claim.status == "Unpaid") + .limit(MAX_QUERY_RESULTS) ) if exact_match: From 6dc8c0340a7d11f30c9917f34657e98c7a0f97a9 Mon Sep 17 00:00:00 2001 From: barredterra <14891507+barredterra@users.noreply.github.com> Date: Thu, 31 Oct 2024 19:36:43 +0100 Subject: [PATCH 2/2] chore: resolve conflicts --- .../bank_reconciliation_tool_beta.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/banking/klarna_kosma_integration/doctype/bank_reconciliation_tool_beta/bank_reconciliation_tool_beta.py b/banking/klarna_kosma_integration/doctype/bank_reconciliation_tool_beta/bank_reconciliation_tool_beta.py index e9703a07..bed2d410 100644 --- a/banking/klarna_kosma_integration/doctype/bank_reconciliation_tool_beta/bank_reconciliation_tool_beta.py +++ b/banking/klarna_kosma_integration/doctype/bank_reconciliation_tool_beta/bank_reconciliation_tool_beta.py @@ -709,12 +709,8 @@ def get_ld_matching_query(bank_account, exact_match, transaction): ) .where(loan_disbursement.docstatus == 1) .where(loan_disbursement.clearance_date.isnull()) -<<<<<<< HEAD .where(loan_disbursement.disbursement_account == bank_account) -======= - .where(loan_disbursement.disbursement_account == common_filters.bank_account) .limit(MAX_QUERY_RESULTS) ->>>>>>> 90ab122 (perf: set a hard limit on query results) ) if exact_match: @@ -762,12 +758,8 @@ def get_lr_matching_query(bank_account, exact_match, transaction): ) .where(loan_repayment.docstatus == 1) .where(loan_repayment.clearance_date.isnull()) -<<<<<<< HEAD .where(loan_repayment.payment_account == bank_account) -======= - .where(loan_repayment.payment_account == common_filters.bank_account) .limit(MAX_QUERY_RESULTS) ->>>>>>> 90ab122 (perf: set a hard limit on query results) ) if frappe.db.has_column("Loan Repayment", "repay_from_salary"):