Skip to content

Commit

Permalink
perf: added caching to XBlockSkillsViewSet list endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
hamza-56 committed Oct 2, 2024
1 parent a79beea commit e593975
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
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
16 changes: 16 additions & 0 deletions taxonomy/api/v1/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
from django.db.models import Count, Prefetch, Sum
from django.shortcuts import get_object_or_404

from edx_django_utils.cache import TieredCache, get_cache_key

from taxonomy.api.filters import SkillNameFilter, XBlocksFilter
from taxonomy.api.permissions import IsOwner
from taxonomy.api.v1.serializers import (
Expand All @@ -40,6 +42,8 @@
XBlockSkills,
)

CACHE_TIMEOUT_XBLOCK_SKILLS_SECONDS = 60 * 60


class TaxonomyAPIViewSetMixin:
"""
Expand Down Expand Up @@ -320,6 +324,18 @@ def get_queryset(self):
),
).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)

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

0 comments on commit e593975

Please sign in to comment.