mirror of
https://github.com/django/django.git
synced 2025-10-27 23:56:08 +00:00
Fixed #21351 -- Replaced memoize with Python's lru_cache.
Replaced the custom, untested memoize with a similar decorator from Python's 3.2 stdlib. Although some minor performance degradation (see ticket), it is expected that in the long run lru_cache will outperform memoize once it is implemented in C. Thanks to EvilDMP for the report and Baptiste Mispelon for the idea of replacing memoize with lru_cache.
This commit is contained in:
committed by
Baptiste Mispelon
parent
6c5f5b9a41
commit
9b7455e918
@@ -4,16 +4,14 @@ import os
|
||||
from django.conf import settings
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.core.files.storage import default_storage, Storage, FileSystemStorage
|
||||
from django.utils.functional import empty, memoize, LazyObject
|
||||
from django.utils.functional import empty, LazyObject
|
||||
from django.utils.module_loading import import_by_path
|
||||
from django.utils._os import safe_join
|
||||
from django.utils import six
|
||||
from django.utils import six, lru_cache
|
||||
|
||||
from django.contrib.staticfiles import utils
|
||||
from django.contrib.staticfiles.storage import AppStaticStorage
|
||||
|
||||
_finders = OrderedDict()
|
||||
|
||||
|
||||
class BaseFinder(object):
|
||||
"""
|
||||
@@ -254,7 +252,8 @@ def get_finders():
|
||||
yield get_finder(finder_path)
|
||||
|
||||
|
||||
def _get_finder(import_path):
|
||||
@lru_cache.lru_cache(maxsize=None)
|
||||
def get_finder(import_path):
|
||||
"""
|
||||
Imports the staticfiles finder class described by import_path, where
|
||||
import_path is the full Python path to the class.
|
||||
@@ -264,4 +263,3 @@ def _get_finder(import_path):
|
||||
raise ImproperlyConfigured('Finder "%s" is not a subclass of "%s"' %
|
||||
(Finder, BaseFinder))
|
||||
return Finder()
|
||||
get_finder = memoize(_get_finder, _finders, 1)
|
||||
|
||||
Reference in New Issue
Block a user