Commit 13682e46 by David Ormsbee

Cache edxmako request context computation.

When capa problem rendering was moved to happen inline on courseware
page loads, we started executing many more Mako templates on sequences
with large numbers of thse problems. To help offset this, we're caching
the context generation (it showed up as the easiest piece of low
hanging fruit on profiles of the courseware index page).

[PERF-261]
parent 9984bbc2
...@@ -19,6 +19,8 @@ from django.template.context import _builtin_context_processors ...@@ -19,6 +19,8 @@ from django.template.context import _builtin_context_processors
from django.utils.module_loading import import_string from django.utils.module_loading import import_string
from util.request import safe_get_host from util.request import safe_get_host
from request_cache.middleware import RequestCache
REQUEST_CONTEXT = threading.local() REQUEST_CONTEXT = threading.local()
...@@ -51,6 +53,12 @@ def get_template_request_context(): ...@@ -51,6 +53,12 @@ def get_template_request_context():
request = getattr(REQUEST_CONTEXT, "request", None) request = getattr(REQUEST_CONTEXT, "request", None)
if not request: if not request:
return None return None
request_cache_dict = RequestCache.get_request_cache().data
cache_key = "edxmako_request_context"
if cache_key in request_cache_dict:
return request_cache_dict[cache_key]
context = RequestContext(request) context = RequestContext(request)
context['is_secure'] = request.is_secure() context['is_secure'] = request.is_secure()
context['site'] = safe_get_host(request) context['site'] = safe_get_host(request)
...@@ -62,4 +70,6 @@ def get_template_request_context(): ...@@ -62,4 +70,6 @@ def get_template_request_context():
for processor in get_template_context_processors(): for processor in get_template_context_processors():
context.update(processor(request)) context.update(processor(request))
request_cache_dict[cache_key] = context
return context return context
...@@ -33,7 +33,6 @@ def marketing_link(name): ...@@ -33,7 +33,6 @@ def marketing_link(name):
possible URLs for certain links. This function is to decides possible URLs for certain links. This function is to decides
which URL should be provided. which URL should be provided.
""" """
# link_map maps URLs from the marketing site to the old equivalent on # link_map maps URLs from the marketing site to the old equivalent on
# the Django site # the Django site
link_map = settings.MKTG_URL_LINK_MAP link_map = settings.MKTG_URL_LINK_MAP
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment