mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Fixed #24590 -- Cached calls to swappable_setting.
Moved the lookup in Field.swappable_setting to Apps, and added an lru_cache to cache the results. Refs #24743 Thanks Marten Kenbeek for the initial work on the patch. Thanks Aymeric Augustin and Tim Graham for the review.
This commit is contained in:
@@ -314,17 +314,8 @@ class RelatedField(Field):
|
||||
if isinstance(self.remote_field.model, six.string_types):
|
||||
to_string = self.remote_field.model
|
||||
else:
|
||||
to_string = "%s.%s" % (
|
||||
self.remote_field.model._meta.app_label,
|
||||
self.remote_field.model._meta.object_name,
|
||||
)
|
||||
# See if anything swapped/swappable matches
|
||||
for model in apps.get_models(include_swapped=True):
|
||||
if model._meta.swapped:
|
||||
if model._meta.swapped == to_string:
|
||||
return model._meta.swappable
|
||||
if ("%s.%s" % (model._meta.app_label, model._meta.object_name)) == to_string and model._meta.swappable:
|
||||
return model._meta.swappable
|
||||
to_string = self.remote_field.model._meta.label
|
||||
return apps.get_swappable_settings_name(to_string)
|
||||
return None
|
||||
|
||||
def set_attributes_from_rel(self):
|
||||
|
||||
@@ -396,7 +396,7 @@ class Options(object):
|
||||
# or as part of validation.
|
||||
return swapped_for
|
||||
|
||||
if '%s.%s' % (swapped_label, swapped_object.lower()) not in (None, self.label_lower):
|
||||
if '%s.%s' % (swapped_label, swapped_object.lower()) != self.label_lower:
|
||||
return swapped_for
|
||||
return None
|
||||
|
||||
|
||||
Reference in New Issue
Block a user