Skip to content

Commit

Permalink
Refs #23919 -- Stopped using django.utils.lru_cache().
Browse files Browse the repository at this point in the history
  • Loading branch information
aaugustin authored and timgraham committed Jan 19, 2017
1 parent 2b281cc commit 3cc5f01
Show file tree
Hide file tree
Showing 21 changed files with 52 additions and 216 deletions.
6 changes: 3 additions & 3 deletions django/apps/registry.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import functools
import sys
import threading
import warnings
from collections import Counter, OrderedDict, defaultdict
from functools import partial

from django.core.exceptions import AppRegistryNotReady, ImproperlyConfigured
from django.utils import lru_cache

from .config import AppConfig

Expand Down Expand Up @@ -156,7 +156,7 @@ def get_app_config(self, app_label):
raise LookupError(message)

# This method is performance-critical at least for Django's test suite.
@lru_cache.lru_cache(maxsize=None)
@functools.lru_cache(maxsize=None)
def get_models(self, include_auto_created=False, include_swapped=False):
"""
Returns a list of all installed models.
Expand Down Expand Up @@ -268,7 +268,7 @@ def get_registered_model(self, app_label, model_name):
"Model '%s.%s' not registered." % (app_label, model_name))
return model

@lru_cache.lru_cache(maxsize=None)
@functools.lru_cache(maxsize=None)
def get_swappable_settings_name(self, to_string):
"""
For a given model string (e.g. "auth.User"), return the name of the
Expand Down
5 changes: 3 additions & 2 deletions django/conf/urls/i18n.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import functools

from django.conf import settings
from django.conf.urls import url
from django.urls import LocaleRegexURLResolver, get_resolver
from django.utils import lru_cache
from django.views.i18n import set_language


Expand All @@ -18,7 +19,7 @@ def i18n_patterns(*urls, **kwargs):
return [LocaleRegexURLResolver(list(urls), prefix_default_language=prefix_default_language)]


@lru_cache.lru_cache(maxsize=None)
@functools.lru_cache(maxsize=None)
def is_language_prefix_patterns_used(urlconf):
"""
Return a tuple of two booleans: (
Expand Down
6 changes: 3 additions & 3 deletions django/contrib/auth/hashers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import base64
import binascii
import functools
import hashlib
import importlib
import warnings
Expand All @@ -9,7 +10,6 @@
from django.core.exceptions import ImproperlyConfigured
from django.core.signals import setting_changed
from django.dispatch import receiver
from django.utils import lru_cache
from django.utils.crypto import (
constant_time_compare, get_random_string, pbkdf2,
)
Expand Down Expand Up @@ -82,7 +82,7 @@ def make_password(password, salt=None, hasher='default'):
return hasher.encode(password, salt)


@lru_cache.lru_cache()
@functools.lru_cache()
def get_hashers():
hashers = []
for hasher_path in settings.PASSWORD_HASHERS:
Expand All @@ -95,7 +95,7 @@ def get_hashers():
return hashers


@lru_cache.lru_cache()
@functools.lru_cache()
def get_hashers_by_algorithm():
return {hasher.algorithm: hasher for hasher in get_hashers()}

Expand Down
4 changes: 2 additions & 2 deletions django/contrib/auth/password_validation.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import functools
import gzip
import os
import re
Expand All @@ -7,7 +8,6 @@
from django.core.exceptions import (
FieldDoesNotExist, ImproperlyConfigured, ValidationError,
)
from django.utils import lru_cache
from django.utils._os import upath
from django.utils.encoding import force_text
from django.utils.functional import lazy
Expand All @@ -16,7 +16,7 @@
from django.utils.translation import ugettext as _, ungettext


@lru_cache.lru_cache(maxsize=None)
@functools.lru_cache(maxsize=None)
def get_default_password_validators():
return get_password_validators(settings.AUTH_PASSWORD_VALIDATORS)

Expand Down
4 changes: 2 additions & 2 deletions django/contrib/staticfiles/finders.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import functools
import os
from collections import OrderedDict

Expand All @@ -8,7 +9,6 @@
from django.core.files.storage import (
FileSystemStorage, Storage, default_storage,
)
from django.utils import lru_cache
from django.utils._os import safe_join
from django.utils.functional import LazyObject, empty
from django.utils.module_loading import import_string
Expand Down Expand Up @@ -264,7 +264,7 @@ def get_finders():
yield get_finder(finder_path)


@lru_cache.lru_cache(maxsize=None)
@functools.lru_cache(maxsize=None)
def get_finder(import_path):
"""
Imports the staticfiles finder class described by import_path, where
Expand Down
5 changes: 3 additions & 2 deletions django/core/management/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import functools
import os
import pkgutil
import sys
Expand All @@ -12,7 +13,7 @@
BaseCommand, CommandError, CommandParser, handle_default_options,
)
from django.core.management.color import color_style
from django.utils import autoreload, lru_cache
from django.utils import autoreload
from django.utils._os import npath, upath
from django.utils.encoding import force_text

Expand All @@ -39,7 +40,7 @@ class instance. All errors raised by the import process
return module.Command()


@lru_cache.lru_cache(maxsize=None)
@functools.lru_cache(maxsize=None)
def get_commands():
"""
Returns a dictionary mapping command names to their callback applications.
Expand Down
5 changes: 3 additions & 2 deletions django/core/management/color.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
Sets up the terminal color scheme.
"""

import functools
import os
import sys

from django.utils import lru_cache, termcolors
from django.utils import termcolors


def supports_color():
Expand Down Expand Up @@ -57,7 +58,7 @@ def style_func(x):
return style


@lru_cache.lru_cache(maxsize=None)
@functools.lru_cache(maxsize=None)
def no_style():
"""
Returns a Style object with no color scheme.
Expand Down
4 changes: 2 additions & 2 deletions django/core/management/commands/loaddata.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import functools
import glob
import gzip
import os
Expand All @@ -16,7 +17,6 @@
DEFAULT_DB_ALIAS, DatabaseError, IntegrityError, connections, router,
transaction,
)
from django.utils import lru_cache
from django.utils._os import upath
from django.utils.encoding import force_text
from django.utils.functional import cached_property
Expand Down Expand Up @@ -202,7 +202,7 @@ def load_label(self, fixture_label):
RuntimeWarning
)

@lru_cache.lru_cache(maxsize=None)
@functools.lru_cache(maxsize=None)
def find_fixtures(self, fixture_label):
"""
Finds fixture files for a given label.
Expand Down
4 changes: 2 additions & 2 deletions django/db/models/fields/related.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import functools
import inspect
from functools import partial

Expand All @@ -13,7 +14,6 @@
from django.db.models.utils import make_model_tuple
from django.utils.encoding import force_text
from django.utils.functional import cached_property, curry
from django.utils.lru_cache import lru_cache
from django.utils.translation import ugettext_lazy as _

from . import Field
Expand Down Expand Up @@ -710,7 +710,7 @@ def get_reverse_path_info(self):
return pathinfos

@classmethod
@lru_cache(maxsize=None)
@functools.lru_cache(maxsize=None)
def get_lookups(cls):
bases = inspect.getmro(cls)
bases = bases[:bases.index(ForeignObject) + 1]
Expand Down
4 changes: 2 additions & 2 deletions django/db/models/query_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
large and/or so that they can be used by other modules without getting into
circular import difficulties.
"""
import functools
import inspect
from collections import namedtuple

from django.db.models.constants import LOOKUP_SEP
from django.utils import tree
from django.utils.lru_cache import lru_cache

# PathInfo is used when converting lookups (fk__somecol). The contents
# describe the relation in Model terms (model Options and Fields for both
Expand Down Expand Up @@ -137,7 +137,7 @@ def _get_lookup(cls, lookup_name):
return cls.get_lookups().get(lookup_name, None)

@classmethod
@lru_cache(maxsize=None)
@functools.lru_cache(maxsize=None)
def get_lookups(cls):
class_lookups = [parent.__dict__.get('class_lookups', {}) for parent in inspect.getmro(cls)]
return cls.merge_dicts(class_lookups)
Expand Down
4 changes: 2 additions & 2 deletions django/forms/renderers.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import functools
import os

from django.conf import settings
from django.template.backends.django import DjangoTemplates
from django.template.loader import get_template
from django.utils import lru_cache
from django.utils._os import upath
from django.utils.functional import cached_property
from django.utils.module_loading import import_string
Expand All @@ -17,7 +17,7 @@ def Jinja2(params):
ROOT = upath(os.path.dirname(__file__))


@lru_cache.lru_cache()
@functools.lru_cache()
def get_default_renderer():
renderer_class = import_string(settings.FORM_RENDERER)
return renderer_class()
Expand Down
5 changes: 3 additions & 2 deletions django/template/engine.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import functools

from django.core.exceptions import ImproperlyConfigured
from django.utils import lru_cache
from django.utils.functional import cached_property
from django.utils.module_loading import import_string

Expand Down Expand Up @@ -52,7 +53,7 @@ def __init__(self, dirs=None, app_dirs=False, context_processors=None,
self.template_builtins = self.get_template_builtins(self.builtins)

@staticmethod
@lru_cache.lru_cache()
@functools.lru_cache()
def get_default():
"""
When only one DjangoTemplates backend is configured, returns it.
Expand Down
4 changes: 2 additions & 2 deletions django/template/utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import functools
import os
from collections import Counter, OrderedDict

from django.apps import apps
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.utils import lru_cache
from django.utils._os import upath
from django.utils.functional import cached_property
from django.utils.module_loading import import_string
Expand Down Expand Up @@ -89,7 +89,7 @@ def all(self):
return [self[alias] for alias in self]


@lru_cache.lru_cache()
@functools.lru_cache()
def get_app_template_dirs(dirname):
"""
Return an iterable of paths of directories to load app templates from.
Expand Down
5 changes: 2 additions & 3 deletions django/urls/resolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from django.core.checks import Warning
from django.core.checks.urls import check_resolver
from django.core.exceptions import ImproperlyConfigured
from django.utils import lru_cache
from django.utils.datastructures import MultiValueDict
from django.utils.encoding import force_str, force_text
from django.utils.functional import cached_property
Expand Down Expand Up @@ -60,15 +59,15 @@ def __repr__(self):
)


@lru_cache.lru_cache(maxsize=None)
@functools.lru_cache(maxsize=None)
def get_resolver(urlconf=None):
if urlconf is None:
from django.conf import settings
urlconf = settings.ROOT_URLCONF
return RegexURLResolver(r'^/', urlconf)


@lru_cache.lru_cache(maxsize=None)
@functools.lru_cache(maxsize=None)
def get_ns_resolver(ns_pattern, resolver):
# Build a namespaced resolver for the given parent URLconf pattern.
# This makes it possible to have captured parameters in the parent
Expand Down
4 changes: 2 additions & 2 deletions django/urls/utils.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import functools
from importlib import import_module

from django.core.exceptions import ViewDoesNotExist
from django.utils import lru_cache
from django.utils.module_loading import module_has_submodule


@lru_cache.lru_cache(maxsize=None)
@functools.lru_cache(maxsize=None)
def get_callable(lookup_view):
"""
Return a callable corresponding to lookup_view.
Expand Down
Loading

0 comments on commit 3cc5f01

Please sign in to comment.