perf: add lru_cache to improve performance with multiple themes
These changes should improve the performance caused by the file I/O when it's running in docker, using lru_cache to save thousands of calls to listdir when running with a handful of themes defined in COMPREHENSIVE_THEME_DIRS.
This commit is contained in:
committed by
David Ormsbee
parent
5deeff3da1
commit
43158404bc
@@ -8,6 +8,8 @@ from path import Path
|
||||
|
||||
from common.djangoapps import edxmako
|
||||
from openedx.core.djangoapps.theming.tests.test_util import with_comprehensive_theme
|
||||
from openedx.core.djangoapps.theming.helpers import get_themes
|
||||
from openedx.core.djangoapps.theming.helpers_dirs import get_theme_dirs
|
||||
from openedx.core.lib.tempdir import create_symlink, delete_symlink, mkdtemp_clean
|
||||
|
||||
|
||||
@@ -20,6 +22,10 @@ class TestComprehensiveTheming(TestCase):
|
||||
# Clear the internal staticfiles caches, to get test isolation.
|
||||
staticfiles.finders.get_finder.cache_clear()
|
||||
|
||||
# Clear cache on get_theme methods.
|
||||
get_themes.cache_clear()
|
||||
get_theme_dirs.cache_clear()
|
||||
|
||||
@with_comprehensive_theme('red-theme')
|
||||
def test_red_footer(self):
|
||||
"""
|
||||
|
||||
@@ -23,6 +23,7 @@ from openedx.core.djangoapps.theming.helpers_dirs import (
|
||||
get_themes_unchecked
|
||||
)
|
||||
from openedx.core.lib.cache_utils import request_cached
|
||||
from functools import lru_cache
|
||||
|
||||
logger = getLogger(__name__) # pylint: disable=invalid-name
|
||||
|
||||
@@ -255,6 +256,7 @@ def theme_exists(theme_name, themes_dir=None):
|
||||
return False
|
||||
|
||||
|
||||
@lru_cache
|
||||
def get_themes(themes_dir=None):
|
||||
"""
|
||||
get a list of all themes known to the system.
|
||||
|
||||
@@ -7,6 +7,7 @@ as the discovery happens during the initial setup of Django settings.
|
||||
import os
|
||||
|
||||
from path import Path
|
||||
from functools import lru_cache
|
||||
|
||||
|
||||
def get_theme_base_dirs_from_settings(theme_base_dirs=None):
|
||||
@@ -49,6 +50,7 @@ def get_themes_unchecked(themes_base_dirs, project_root=None):
|
||||
return themes
|
||||
|
||||
|
||||
@lru_cache
|
||||
def get_theme_dirs(themes_base_dir=None):
|
||||
"""
|
||||
Get all the theme dirs directly under a given base dir.
|
||||
|
||||
@@ -16,6 +16,7 @@ from openedx.core.djangoapps.theming.helpers import (
|
||||
get_themes,
|
||||
strip_site_theme_templates_path
|
||||
)
|
||||
from openedx.core.djangoapps.theming.helpers_dirs import get_theme_dirs
|
||||
from openedx.core.djangoapps.theming.tests.test_util import with_comprehensive_theme
|
||||
from openedx.core.djangolib.testing.utils import skip_unless_cms, skip_unless_lms
|
||||
|
||||
@@ -23,6 +24,15 @@ from openedx.core.djangolib.testing.utils import skip_unless_cms, skip_unless_lm
|
||||
class TestHelpers(TestCase):
|
||||
"""Test comprehensive theming helper functions."""
|
||||
|
||||
def setUp(self):
|
||||
"""
|
||||
Clear cache on get_theme methods.
|
||||
"""
|
||||
super().setUp()
|
||||
|
||||
get_themes.cache_clear()
|
||||
get_theme_dirs.cache_clear()
|
||||
|
||||
def test_get_themes(self):
|
||||
"""
|
||||
Tests template paths are returned from enabled theme.
|
||||
|
||||
Reference in New Issue
Block a user