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: added caching to XBlockSkillsViewSet list endpoint #208

Merged
merged 2 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ Change Log

Unreleased

[1.54.0] - 2024-10-02
---------------------
* perf: Added caching to `XBlockSkillsViewSet` list endpoint to improve performance and reduce redundant database queries

[1.53.0] - 2024-08-22
---------------------
* perf: Introduced db_index on the `created` and `is_blacklisted` fields in `XBlockSkillData` model
Expand Down
2 changes: 1 addition & 1 deletion taxonomy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
# 2. MINOR version when you add functionality in a backwards compatible manner, and
# 3. PATCH version when you make backwards compatible bug fixes.
# More details can be found at https://semver.org/
__version__ = '1.53.0'
__version__ = '1.54.0'

default_app_config = 'taxonomy.apps.TaxonomyConfig' # pylint: disable=invalid-name
15 changes: 15 additions & 0 deletions taxonomy/api/v1/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from collections import OrderedDict

from django_filters.rest_framework import DjangoFilterBackend
from edx_django_utils.cache import TieredCache, get_cache_key
from rest_framework import permissions
from rest_framework.filters import OrderingFilter
from rest_framework.generics import ListAPIView, RetrieveAPIView
Expand All @@ -27,6 +28,7 @@
SkillsQuizSerializer,
XBlocksSkillsSerializer,
)
from taxonomy.constants import CACHE_TIMEOUT_XBLOCK_SKILLS_SECONDS
from taxonomy.models import (
CourseSkills,
Job,
Expand Down Expand Up @@ -320,6 +322,19 @@
),
).only('id', 'skills', 'usage_key', 'requires_verification', 'auto_processed', 'hash_content')

def list(self, request, *args, **kwargs):
cache_key = get_cache_key(domain='taxonomy', subdomain='xblock_skills', params=request.query_params)

cached_response = TieredCache.get_cached_response(cache_key)
if cached_response.is_found:
return Response(cached_response.value)

Check warning on line 330 in taxonomy/api/v1/views.py

View check run for this annotation

Codecov / codecov/patch

taxonomy/api/v1/views.py#L330

Added line #L330 was not covered by tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add a unit test for this.


response = super().list(request, *args, **kwargs)

TieredCache.set_all_tiers(cache_key, response.data, CACHE_TIMEOUT_XBLOCK_SKILLS_SECONDS)

return response


class JobPathAPIView(TaxonomyAPIViewSetMixin, RetrieveAPIView):
"""
Expand Down
2 changes: 2 additions & 0 deletions taxonomy/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,5 @@ def get_job_posting_query_filter(jobs=None):
JOB_SOURCE_COURSE_SKILL = 'course_skill'
JOB_SOURCE_INDUSTRY = 'industry'
JOB_SKILLS_URL_NAME = 'job-skills'

CACHE_TIMEOUT_XBLOCK_SKILLS_SECONDS = 60 * 60
Loading