[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:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user