[PERF] account.chart.template existing_accounting slow

By adding an explicit order to the queries within `existing_accounting` the PostgreSQL query cost drops to `cost=0.84..1.78 rows=1 width=4` from `cost=13061.20..18895.19 rows=1 width=24` (on my local dev machine).

closes odoo/odoo#112842

X-original-commit: ab34d6b0273c6766757f0596ca5f62458a9d5ab5
Signed-off-by: John Laterre (jol) <jol@odoo.com>
This commit is contained in:
Karl
2023-02-16 10:05:20 +01:00
committed by Karl Southern
parent e81d149ff2
commit 1439299e2e
+2 -2
View File
@@ -562,9 +562,9 @@ class AccountChartTemplate(models.Model):
"""
model_to_check = ['account.payment', 'account.bank.statement.line']
for model in model_to_check:
if self.env[model].sudo().search([('company_id', '=', company_id.id)], limit=1):
if self.env[model].sudo().search([('company_id', '=', company_id.id)], order="id DESC", limit=1):
return True
if self.env['account.move'].sudo().search([('company_id', '=', company_id.id), ('state', '!=', 'draft')], limit=1):
if self.env['account.move'].sudo().search([('company_id', '=', company_id.id), ('state', '!=', 'draft')], order="id DESC", limit=1):
return True
return False