mirror of
https://github.com/django/django.git
synced 2025-10-03 23:34:47 +00:00
Optimized Model instantiation a bit.
* Avoid some unnecessary attribute lookups, e.g. access signals directly rather than from module * Alias some repeat accesses inside the method to use the slightly faster local lookups * Use tuple to iterate remaining kwargs as it's faster to construct * Cache Field.get_default() to avoid running through all the logic on every call * Use a cached list of the properties on the model class to avoid repeat isinstance() calls
This commit is contained in:
parent
f94475e526
commit
d2a26c1a90
3 changed files with 60 additions and 28 deletions
|
@ -883,3 +883,14 @@ class Options(object):
|
|||
@has_auto_field.setter
|
||||
def has_auto_field(self, value):
|
||||
pass
|
||||
|
||||
@cached_property
|
||||
def _property_names(self):
|
||||
"""
|
||||
Return a set of the names of the properties defined on the model.
|
||||
Internal helper for model initialization.
|
||||
"""
|
||||
return frozenset({
|
||||
attr for attr in
|
||||
dir(self.model) if isinstance(getattr(self.model, attr), property)
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue