mirror of
https://github.com/django/django.git
synced 2025-03-10 01:12:53 +00:00
Refs #34233 -- Used @functools.cache.
Python 3.9+ supports @functools.cache as an alias for @functools.lru_cache(maxsize=None).
This commit is contained in:
parent
23e8868862
commit
4470c2405c
@ -165,7 +165,7 @@ class Apps:
|
|||||||
raise LookupError(message)
|
raise LookupError(message)
|
||||||
|
|
||||||
# This method is performance-critical at least for Django's test suite.
|
# This method is performance-critical at least for Django's test suite.
|
||||||
@functools.lru_cache(maxsize=None)
|
@functools.cache
|
||||||
def get_models(self, include_auto_created=False, include_swapped=False):
|
def get_models(self, include_auto_created=False, include_swapped=False):
|
||||||
"""
|
"""
|
||||||
Return a list of all installed models.
|
Return a list of all installed models.
|
||||||
@ -280,14 +280,14 @@ class Apps:
|
|||||||
raise LookupError("Model '%s.%s' not registered." % (app_label, model_name))
|
raise LookupError("Model '%s.%s' not registered." % (app_label, model_name))
|
||||||
return model
|
return model
|
||||||
|
|
||||||
@functools.lru_cache(maxsize=None)
|
@functools.cache
|
||||||
def get_swappable_settings_name(self, to_string):
|
def get_swappable_settings_name(self, to_string):
|
||||||
"""
|
"""
|
||||||
For a given model string (e.g. "auth.User"), return the name of the
|
For a given model string (e.g. "auth.User"), return the name of the
|
||||||
corresponding settings name if it refers to a swappable model. If the
|
corresponding settings name if it refers to a swappable model. If the
|
||||||
referred model is not swappable, return None.
|
referred model is not swappable, return None.
|
||||||
|
|
||||||
This method is decorated with lru_cache because it's performance
|
This method is decorated with @functools.cache because it's performance
|
||||||
critical when it comes to migrations. Since the swappable settings don't
|
critical when it comes to migrations. Since the swappable settings don't
|
||||||
change after Django has loaded the settings, there is no reason to get
|
change after Django has loaded the settings, there is no reason to get
|
||||||
the respective settings attribute over and over again.
|
the respective settings attribute over and over again.
|
||||||
|
@ -20,7 +20,7 @@ def i18n_patterns(*urls, prefix_default_language=True):
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@functools.lru_cache(maxsize=None)
|
@functools.cache
|
||||||
def is_language_prefix_patterns_used(urlconf):
|
def is_language_prefix_patterns_used(urlconf):
|
||||||
"""
|
"""
|
||||||
Return a tuple of two booleans: (
|
Return a tuple of two booleans: (
|
||||||
|
@ -17,7 +17,7 @@ from django.utils.translation import gettext as _
|
|||||||
from django.utils.translation import ngettext
|
from django.utils.translation import ngettext
|
||||||
|
|
||||||
|
|
||||||
@functools.lru_cache(maxsize=None)
|
@functools.cache
|
||||||
def get_default_password_validators():
|
def get_default_password_validators():
|
||||||
return get_password_validators(settings.AUTH_PASSWORD_VALIDATORS)
|
return get_password_validators(settings.AUTH_PASSWORD_VALIDATORS)
|
||||||
|
|
||||||
|
@ -312,7 +312,7 @@ def get_finders():
|
|||||||
yield get_finder(finder_path)
|
yield get_finder(finder_path)
|
||||||
|
|
||||||
|
|
||||||
@functools.lru_cache(maxsize=None)
|
@functools.cache
|
||||||
def get_finder(import_path):
|
def get_finder(import_path):
|
||||||
"""
|
"""
|
||||||
Import the staticfiles finder class described by import_path, where
|
Import the staticfiles finder class described by import_path, where
|
||||||
|
@ -49,7 +49,7 @@ def load_command_class(app_name, name):
|
|||||||
return module.Command()
|
return module.Command()
|
||||||
|
|
||||||
|
|
||||||
@functools.lru_cache(maxsize=None)
|
@functools.cache
|
||||||
def get_commands():
|
def get_commands():
|
||||||
"""
|
"""
|
||||||
Return a dictionary mapping command names to their callback applications.
|
Return a dictionary mapping command names to their callback applications.
|
||||||
|
@ -96,7 +96,7 @@ def make_style(config_string=""):
|
|||||||
return style
|
return style
|
||||||
|
|
||||||
|
|
||||||
@functools.lru_cache(maxsize=None)
|
@functools.cache
|
||||||
def no_style():
|
def no_style():
|
||||||
"""
|
"""
|
||||||
Return a Style object with no color scheme.
|
Return a Style object with no color scheme.
|
||||||
|
@ -311,7 +311,7 @@ class Command(BaseCommand):
|
|||||||
fixture_files_in_dir.append((candidate, fixture_dir, fixture_name))
|
fixture_files_in_dir.append((candidate, fixture_dir, fixture_name))
|
||||||
return fixture_files_in_dir
|
return fixture_files_in_dir
|
||||||
|
|
||||||
@functools.lru_cache(maxsize=None)
|
@functools.cache
|
||||||
def find_fixtures(self, fixture_label):
|
def find_fixtures(self, fixture_label):
|
||||||
"""Find fixture files for a given label."""
|
"""Find fixture files for a given label."""
|
||||||
if fixture_label == READ_STDIN:
|
if fixture_label == READ_STDIN:
|
||||||
|
@ -857,7 +857,7 @@ class ForeignObject(RelatedField):
|
|||||||
return self.get_reverse_path_info()
|
return self.get_reverse_path_info()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@functools.lru_cache(maxsize=None)
|
@functools.cache
|
||||||
def get_class_lookups(cls):
|
def get_class_lookups(cls):
|
||||||
bases = inspect.getmro(cls)
|
bases = inspect.getmro(cls)
|
||||||
bases = bases[: bases.index(ForeignObject) + 1]
|
bases = bases[: bases.index(ForeignObject) + 1]
|
||||||
|
@ -213,7 +213,7 @@ class RegisterLookupMixin:
|
|||||||
def _get_lookup(self, lookup_name):
|
def _get_lookup(self, lookup_name):
|
||||||
return self.get_lookups().get(lookup_name, None)
|
return self.get_lookups().get(lookup_name, None)
|
||||||
|
|
||||||
@functools.lru_cache(maxsize=None)
|
@functools.cache
|
||||||
def get_class_lookups(cls):
|
def get_class_lookups(cls):
|
||||||
class_lookups = [
|
class_lookups = [
|
||||||
parent.__dict__.get("class_lookups", {}) for parent in inspect.getmro(cls)
|
parent.__dict__.get("class_lookups", {}) for parent in inspect.getmro(cls)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
|
import functools
|
||||||
import uuid
|
import uuid
|
||||||
from functools import lru_cache
|
|
||||||
|
|
||||||
|
|
||||||
class IntConverter:
|
class IntConverter:
|
||||||
@ -57,7 +57,7 @@ def register_converter(converter, type_name):
|
|||||||
get_converters.cache_clear()
|
get_converters.cache_clear()
|
||||||
|
|
||||||
|
|
||||||
@lru_cache(maxsize=None)
|
@functools.cache
|
||||||
def get_converters():
|
def get_converters():
|
||||||
return {**DEFAULT_CONVERTERS, **REGISTERED_CONVERTERS}
|
return {**DEFAULT_CONVERTERS, **REGISTERED_CONVERTERS}
|
||||||
|
|
||||||
|
@ -108,12 +108,12 @@ def get_resolver(urlconf=None):
|
|||||||
return _get_cached_resolver(urlconf)
|
return _get_cached_resolver(urlconf)
|
||||||
|
|
||||||
|
|
||||||
@functools.lru_cache(maxsize=None)
|
@functools.cache
|
||||||
def _get_cached_resolver(urlconf=None):
|
def _get_cached_resolver(urlconf=None):
|
||||||
return URLResolver(RegexPattern(r"^/"), urlconf)
|
return URLResolver(RegexPattern(r"^/"), urlconf)
|
||||||
|
|
||||||
|
|
||||||
@functools.lru_cache(maxsize=None)
|
@functools.cache
|
||||||
def get_ns_resolver(ns_pattern, resolver, converters):
|
def get_ns_resolver(ns_pattern, resolver, converters):
|
||||||
# Build a namespaced resolver for the given parent URLconf pattern.
|
# Build a namespaced resolver for the given parent URLconf pattern.
|
||||||
# This makes it possible to have captured parameters in the parent
|
# This makes it possible to have captured parameters in the parent
|
||||||
|
@ -5,7 +5,7 @@ from django.core.exceptions import ViewDoesNotExist
|
|||||||
from django.utils.module_loading import module_has_submodule
|
from django.utils.module_loading import module_has_submodule
|
||||||
|
|
||||||
|
|
||||||
@functools.lru_cache(maxsize=None)
|
@functools.cache
|
||||||
def get_callable(lookup_view):
|
def get_callable(lookup_view):
|
||||||
"""
|
"""
|
||||||
Return a callable corresponding to lookup_view.
|
Return a callable corresponding to lookup_view.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user