From 963fa23483d97c3273ebde6080f7755ea88ba5cc Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Tue, 16 Apr 2024 09:45:46 +0200 Subject: [PATCH] [IMP] account_reconciliation_widget: Performance opening reconciliation widget There was an unneeded mapped of the initial statements that fetches a lot of data from statement lines that are not going to be used later, so let's remove it and optimize a bit the initial opening time. In a customer database, we have improved the opening time from 120 seconds to 15. TT48753 --- .../models/reconciliation_widget.py | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/account_reconciliation_widget/models/reconciliation_widget.py b/account_reconciliation_widget/models/reconciliation_widget.py index 7e823c9b..a151211a 100644 --- a/account_reconciliation_widget/models/reconciliation_widget.py +++ b/account_reconciliation_widget/models/reconciliation_widget.py @@ -308,12 +308,6 @@ class AccountReconciliation(models.AbstractModel): """ if not bank_statement_line_ids: return {} - bank_statements = ( - self.env["account.bank.statement.line"] - .browse(bank_statement_line_ids) - .mapped("statement_id") - ) - query = """ SELECT line.id FROM account_bank_statement_line line @@ -340,18 +334,17 @@ class AccountReconciliation(models.AbstractModel): [line["st_line"]["id"] for line in results["lines"]] ) bank_statements_left = bank_statement_lines_left.mapped("statement_id") - + data = bank_statements_left.read(["name", "journal_id"]) + data = data and data[0] or {} results.update( { "statement_id": len(bank_statements_left) == 1 - and bank_statements_left.id + and bank_statements_left[0].id or False, "statement_name": len(bank_statements_left) == 1 - and bank_statements_left.name - or False, - "journal_id": bank_statements - and bank_statements[0].journal_id.id + and data.get("name") or False, + "journal_id": data and data.get("journal_id", [False])[0] or False, "notifications": [], } )