[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) <odo@openerp.com>
This commit is contained in:
Moisés López
2020-09-01 23:41:42 +00:00
parent d8e210e8e1
commit e332320e64
@@ -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):