[IMP] fields: faster record.id access
This is a partial backport of revision ed32700925132943fc4957ae2f43deaeeec7a278 to speed up the access of browse record id field.
This commit is contained in:
committed by
Raphael Collet
parent
5a7a06a71b
commit
600c8b3e65
+8
-2
@@ -2528,9 +2528,15 @@ class Id(Field):
|
||||
def __get__(self, record, owner):
|
||||
if record is None:
|
||||
return self # the field is accessed through the class owner
|
||||
if not record:
|
||||
|
||||
# the code below is written to make record.id as quick as possible
|
||||
ids = record._ids
|
||||
size = len(ids)
|
||||
if size is 0:
|
||||
return False
|
||||
return record.ensure_one()._ids[0]
|
||||
elif size is 1:
|
||||
return ids[0]
|
||||
raise ValueError("Expected singleton: %s" % record)
|
||||
|
||||
def __set__(self, record, value):
|
||||
raise TypeError("field 'id' cannot be assigned")
|
||||
|
||||
Reference in New Issue
Block a user