mirror of
https://github.com/django/django.git
synced 2024-12-22 17:16:24 +00:00
Optimized Model.refresh_from_db(fields=...) by using a set.
This commit is contained in:
parent
0c690c6001
commit
74f7fe3f3d
@ -691,8 +691,8 @@ class Model(AltersData, metaclass=ModelBase):
|
|||||||
self._prefetched_objects_cache = {}
|
self._prefetched_objects_cache = {}
|
||||||
else:
|
else:
|
||||||
prefetched_objects_cache = getattr(self, "_prefetched_objects_cache", ())
|
prefetched_objects_cache = getattr(self, "_prefetched_objects_cache", ())
|
||||||
fields = list(fields)
|
fields = set(fields)
|
||||||
for field in list(fields):
|
for field in fields.copy():
|
||||||
if field in prefetched_objects_cache:
|
if field in prefetched_objects_cache:
|
||||||
del prefetched_objects_cache[field]
|
del prefetched_objects_cache[field]
|
||||||
fields.remove(field)
|
fields.remove(field)
|
||||||
@ -717,11 +717,11 @@ class Model(AltersData, metaclass=ModelBase):
|
|||||||
if fields is not None:
|
if fields is not None:
|
||||||
db_instance_qs = db_instance_qs.only(*fields)
|
db_instance_qs = db_instance_qs.only(*fields)
|
||||||
elif deferred_fields:
|
elif deferred_fields:
|
||||||
fields = [
|
fields = {
|
||||||
f.attname
|
f.attname
|
||||||
for f in self._meta.concrete_fields
|
for f in self._meta.concrete_fields
|
||||||
if f.attname not in deferred_fields
|
if f.attname not in deferred_fields
|
||||||
]
|
}
|
||||||
db_instance_qs = db_instance_qs.only(*fields)
|
db_instance_qs = db_instance_qs.only(*fields)
|
||||||
|
|
||||||
db_instance = db_instance_qs.get()
|
db_instance = db_instance_qs.get()
|
||||||
|
Loading…
Reference in New Issue
Block a user