#31680: Preventing DeferredAttribute.__ get__() unnecessary calls.
-------------------------------------+-------------------------------------
Reporter: Sultan | Owner: Sultan
Type: | Status: assigned
Cleanup/optimization |
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Sultan):
Replying to [comment:4 felixxm]: Yes you are right. I changed the code.
Now it has become much easier and better. Thank you.
{{{
def __get__(self, instance, cls=None):
"""
Retrieve and caches the value from the datastore on the first
lookup.
Return the cached value.
"""
if instance is None:
return self
data = instance.__dict__
field_name = self.field.attname
if field_name not in data:
# Let's see if the field is part of the parent chain. If so we
# might be able to reuse the already loaded value. Refs
#18343.
val = self._check_parent_chain(instance)
if val is None:
instance.refresh_from_db(fields=[field_name])
else:
data[field_name] = val
return data[field_name]
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/31680#comment:5>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/067.bcec8a4d8d20c46b1988f46ec353feb0%40djangoproject.com.