Merge pull request #16601 from edx/efischer/EDU-1731_memoize
Memoize common lookups during request
This commit is contained in:
@@ -11,6 +11,7 @@ from django.conf import settings
|
||||
from mako.exceptions import TopLevelLookupException
|
||||
from mako.lookup import TemplateLookup
|
||||
|
||||
from request_cache.middleware import request_cached
|
||||
from openedx.core.djangoapps.theming.helpers import get_template as themed_template
|
||||
from openedx.core.djangoapps.theming.helpers import get_template_path_with_theme, strip_site_theme_templates_path
|
||||
|
||||
@@ -107,6 +108,7 @@ def add_lookup(namespace, directory, package=None, prepend=False):
|
||||
templates.add_directory(directory, prepend=prepend)
|
||||
|
||||
|
||||
@request_cached
|
||||
def lookup_template(namespace, name):
|
||||
"""
|
||||
Look up a Mako template by namespace and name.
|
||||
|
||||
@@ -19,14 +19,17 @@ from openedx.core.djangoapps.theming.helpers_dirs import (
|
||||
get_theme_dirs,
|
||||
get_themes_unchecked
|
||||
)
|
||||
from request_cache.middleware import RequestCache
|
||||
from request_cache.middleware import RequestCache, request_cached
|
||||
|
||||
logger = getLogger(__name__) # pylint: disable=invalid-name
|
||||
|
||||
|
||||
@request_cached
|
||||
def get_template_path(relative_path, **kwargs):
|
||||
"""
|
||||
This is a proxy function to hide microsite_configuration behind comprehensive theming.
|
||||
|
||||
The calculated value is cached for the lifetime of the current request.
|
||||
"""
|
||||
# We need to give priority to theming over microsites
|
||||
# So, we apply microsite override only if there is no associated site theme
|
||||
|
||||
@@ -12,6 +12,7 @@ from openedx.core.djangoapps.theming import helpers as theming_helpers
|
||||
from openedx.core.djangoapps.theming.helpers import get_template_path_with_theme, strip_site_theme_templates_path, \
|
||||
get_themes, Theme, get_theme_base_dir
|
||||
from openedx.core.djangolib.testing.utils import skip_unless_cms, skip_unless_lms
|
||||
from request_cache.middleware import RequestCache
|
||||
|
||||
|
||||
class TestHelpers(TestCase):
|
||||
@@ -189,6 +190,8 @@ class TestHelpers(TestCase):
|
||||
mock_microsite_backend.get_template = Mock(return_value="/microsite/about.html")
|
||||
self.assertEqual(theming_helpers.get_template_path("about.html"), "about.html")
|
||||
|
||||
RequestCache.clear_request_cache()
|
||||
|
||||
# if the current site does not have associated SiteTheme then get_template_path should return microsite override
|
||||
with patch(
|
||||
"openedx.core.djangoapps.theming.helpers.current_request_has_associated_site_theme",
|
||||
|
||||
Reference in New Issue
Block a user