From e332320e6481f48331c03792754ff23359877aeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mois=C3=A9s=20L=C3=B3pez?= Date: Tue, 1 Sep 2020 23:37:25 +0000 Subject: [PATCH] [IMP] account_check_printing: speed up dashboard w/ index Install "account_check_printing" module Open "Accounting" icon from the main menu It opens the journal dashboard by default It runs the following search domain in account.payment model: domain = [ ... ('payment_method_id.code', '=', 'check_printing'), ... ] It runs the following query: SELECT "account_payment".id FROM "account_payment" WHERE ... AND ("account_payment"."payment_method_id" in ($2))) ... The average duration of this query is 37ms It query is ran for each journal created If you have created 600 journals (real case) so it will run 600 times It will spend more than 22 seconds opening this dashboard After that, you are available to create accounting actions since that the menu is not available before of this dashboard So, it is important to open it faster Creating the following index: - account_payment(payment_method_id) The average duration of the last query is reduced to 0.935ms instead. It means, it will spend 0.5s opening this important dashboard with 600 journals 44x faster closes odoo/odoo#56831 Signed-off-by: Olivier Dony (odo) --- addons/account_check_printing/models/account_payment.py | 1 + 1 file changed, 1 insertion(+) diff --git a/addons/account_check_printing/models/account_payment.py b/addons/account_check_printing/models/account_payment.py index 7325186f598..555fd9b60a4 100644 --- a/addons/account_check_printing/models/account_payment.py +++ b/addons/account_check_printing/models/account_payment.py @@ -26,6 +26,7 @@ class AccountPayment(models.Model): help="The selected journal is configured to print check numbers. If your pre-printed check paper already has numbers " "or if the current numbering is wrong, you can change it in the journal configuration page.", ) + payment_method_id = fields.Many2one(index=True) @api.constrains('check_number', 'journal_id') def _constrains_check_number(self):