Memoize common lookups during request

Prevents repeated memcached lookups on functions whose values should
remain static for the lifetime of a request.

EDUCATOR-1731
This commit is contained in:
Eric Fischer
2017-11-16 16:02:02 -05:00
parent f5d2741c34
commit 2e3f871c12
3 changed files with 9 additions and 1 deletions

View File

@@ -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

View File

@@ -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",