Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: add lru_cache to improve performance with multiple themes #31090

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lms/djangoapps/courseware/tests/test_comprehensive_theming.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

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


Expand All @@ -20,6 +22,10 @@ def setUp(self):
# 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):
"""
Expand Down
2 changes: 2 additions & 0 deletions openedx/core/djangoapps/theming/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
get_themes_unchecked
)
from openedx.core.lib.cache_utils import request_cached
from functools import lru_cache

logger = getLogger(__name__) # pylint: disable=invalid-name

Expand Down Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions openedx/core/djangoapps/theming/helpers_dirs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import os

from path import Path
from functools import lru_cache


def get_theme_base_dirs_from_settings(theme_base_dirs=None):
Expand Down Expand Up @@ -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.
Expand Down
10 changes: 10 additions & 0 deletions openedx/core/djangoapps/theming/tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,23 @@
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


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.
Expand Down