Refs #28459 -- Improved performance of Model.from_db() when fields are deferred.

This commit is contained in:
Sergey Fedoseev 2017-08-02 18:16:36 +05:00 committed by Tim Graham
parent 7bd9639406
commit 78f7f68021
1 changed files with 5 additions and 3 deletions

View File

@ -489,9 +489,11 @@ class Model(metaclass=ModelBase):
@classmethod
def from_db(cls, db, field_names, values):
if len(values) != len(cls._meta.concrete_fields):
values = list(values)
values.reverse()
values = [values.pop() if f.attname in field_names else DEFERRED for f in cls._meta.concrete_fields]
values_iter = iter(values)
values = [
next(values_iter) if f.attname in field_names else DEFERRED
for f in cls._meta.concrete_fields
]
new = cls(*values)
new._state.adding = False
new._state.db = db