mirror of https://github.com/django/django.git
Refs #28459 -- Improved performance of Model.from_db() when fields are deferred.
This commit is contained in:
parent
7bd9639406
commit
78f7f68021
|
@ -489,9 +489,11 @@ class Model(metaclass=ModelBase):
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_db(cls, db, field_names, values):
|
def from_db(cls, db, field_names, values):
|
||||||
if len(values) != len(cls._meta.concrete_fields):
|
if len(values) != len(cls._meta.concrete_fields):
|
||||||
values = list(values)
|
values_iter = iter(values)
|
||||||
values.reverse()
|
values = [
|
||||||
values = [values.pop() if f.attname in field_names else DEFERRED for f in cls._meta.concrete_fields]
|
next(values_iter) if f.attname in field_names else DEFERRED
|
||||||
|
for f in cls._meta.concrete_fields
|
||||||
|
]
|
||||||
new = cls(*values)
|
new = cls(*values)
|
||||||
new._state.adding = False
|
new._state.adding = False
|
||||||
new._state.db = db
|
new._state.db = db
|
||||||
|
|
Loading…
Reference in New Issue