[IMP] fields: faster convert_to_record for many2one fields
Use `env.registry` instead of `env` to get the comodel as a class instead of an instance, which saves one call to `_browse` each time we access a relational field. This saves time because of the cost of `object.__new__` and prefetch update in `_browse`.
This commit is contained in:
committed by
Raphael Collet
parent
368751b938
commit
681ff1aec1
+4
-2
@@ -1978,7 +1978,8 @@ class Many2one(_Relational):
|
||||
return ()
|
||||
|
||||
def convert_to_record(self, value, record):
|
||||
return record.env[self.comodel_name]._browse(value, record.env, record._prefetch)
|
||||
# use registry to avoid creating a recordset for the model
|
||||
return record.env.registry[self.comodel_name]._browse(value, record.env, record._prefetch)
|
||||
|
||||
def convert_to_read(self, value, record, use_name_get=True):
|
||||
if use_name_get and value:
|
||||
@@ -2094,7 +2095,8 @@ class _RelationalMulti(_Relational):
|
||||
raise ValueError("Wrong value for %s: %s" % (self, value))
|
||||
|
||||
def convert_to_record(self, value, record):
|
||||
return record.env[self.comodel_name]._browse(value, record.env, record._prefetch)
|
||||
# use registry to avoid creating a recordset for the model
|
||||
return record.env.registry[self.comodel_name]._browse(value, record.env, record._prefetch)
|
||||
|
||||
def convert_to_read(self, value, record, use_name_get=True):
|
||||
return value.ids
|
||||
|
||||
Reference in New Issue
Block a user