Skip to content

Commit

Permalink
[FIX] base: use cached field_id in ir.property
Browse files Browse the repository at this point in the history
On ir.property model, do get the field_id using the cached result from
ir.model.fields _get_id() method instead of issuing a direct SQL query

OPW-2067461

closes odoo#53275

X-original-commit: 47f64ed
Signed-off-by: Raphael Collet (rco) <[email protected]>
  • Loading branch information
xavieralt authored and rco-odoo committed Jun 19, 2020
1 parent 28d7beb commit 63692c7
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions odoo/addons/base/models/ir_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,11 @@ def _get_property(self, name, model, res_id):
return self.browse(())

def _get_domain(self, prop_name, model):
self._cr.execute("SELECT id FROM ir_model_fields WHERE name=%s AND model=%s", (prop_name, model))
res = self._cr.fetchone()
if not res:
field_id = self.env['ir.model.fields']._get_id(model, prop_name)
if not field_id:
return None
company_id = self._context.get('force_company') or self.env.company.id
return [('fields_id', '=', res[0]), ('company_id', 'in', [company_id, False])]
return [('fields_id', '=', field_id), ('company_id', 'in', [company_id, False])]

@api.model
def get_multi(self, name, model, ids):
Expand All @@ -219,7 +218,7 @@ def get_multi(self, name, model, ids):
return {}

field = self.env[model]._fields[name]
field_id = self.env['ir.model.fields']._get(model, name).id
field_id = self.env['ir.model.fields']._get_id(model, name)
company_id = (
self._context.get('force_company')
or self.env.company.id
Expand Down Expand Up @@ -301,8 +300,7 @@ def clean(value):
default_value = clean(self.get(name, model))

# retrieve the properties corresponding to the given record ids
self._cr.execute("SELECT id FROM ir_model_fields WHERE name=%s AND model=%s", (name, model))
field_id = self._cr.fetchone()[0]
field_id = self.env['ir.model.fields']._get_id(model, name)
company_id = self.env.context.get('force_company') or self.env.company.id
refs = {('%s,%s' % (model, id)): id for id in values}
props = self.search([
Expand Down

0 comments on commit 63692c7

Please sign in to comment.