From db276e4d9915ae19ec162409a3a106baac03b26a Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Thu, 2 Apr 2020 06:45:54 +0000 Subject: [PATCH] [IMP] core: perform `xmlid_lookup` in pure SQL This saves 3% of the total installation time. X-original-commit: ed2971023edf0ce475e6972598e9d0dfaa88c2b8 --- odoo/addons/base/models/ir_model.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/odoo/addons/base/models/ir_model.py b/odoo/addons/base/models/ir_model.py index cd726c77f29..98a39d0fc85 100644 --- a/odoo/addons/base/models/ir_model.py +++ b/odoo/addons/base/models/ir_model.py @@ -1734,14 +1734,12 @@ class IrModelData(models.Model): Return (id, res_model, res_id) or raise ValueError if not found """ module, name = xmlid.split('.', 1) - xid = self.sudo().search([('module', '=', module), ('name', '=', name)]) - if not xid: + query = "SELECT id, model, res_id FROM ir_model_data WHERE module=%s AND name=%s" + self.env.cr.execute(query, [module, name]) + result = self.env.cr.fetchone() + if not (result and result[2]): raise ValueError('External ID not found in the system: %s' % xmlid) - # the sql constraints ensure us we have only one result - res = xid.read(['model', 'res_id'])[0] - if not res['res_id']: - raise ValueError('External ID not found in the system: %s' % xmlid) - return res['id'], res['model'], res['res_id'] + return result @api.model def xmlid_to_res_model_res_id(self, xmlid, raise_if_not_found=False):