mirror of
https://github.com/django/django.git
synced 2024-11-28 21:43:13 +01: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 = {}
|
||||
else:
|
||||
prefetched_objects_cache = getattr(self, "_prefetched_objects_cache", ())
|
||||
fields = list(fields)
|
||||
for field in list(fields):
|
||||
fields = set(fields)
|
||||
for field in fields.copy():
|
||||
if field in prefetched_objects_cache:
|
||||
del prefetched_objects_cache[field]
|
||||
fields.remove(field)
|
||||
@ -717,11 +717,11 @@ class Model(AltersData, metaclass=ModelBase):
|
||||
if fields is not None:
|
||||
db_instance_qs = db_instance_qs.only(*fields)
|
||||
elif deferred_fields:
|
||||
fields = [
|
||||
fields = {
|
||||
f.attname
|
||||
for f in self._meta.concrete_fields
|
||||
if f.attname not in deferred_fields
|
||||
]
|
||||
}
|
||||
db_instance_qs = db_instance_qs.only(*fields)
|
||||
|
||||
db_instance = db_instance_qs.get()
|
||||
|
Loading…
Reference in New Issue
Block a user