Skip to content

Commit

Permalink
fix: Added temporary cache logging on EnterpriseLearnerEnrollmentViewSet
Browse files Browse the repository at this point in the history
  • Loading branch information
jajjibhai008 committed Sep 25, 2024
1 parent a3eca81 commit 0157a52
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ Unreleased

=========================

[9.2.1] - 2024-09-25
---------------------
* fix: Added temporary cache logging on EnterpriseLearnerEnrollmentViewSet.

[9.2.0] - 2024-09-25
---------------------
* refactor: Performance optimizations for leaderboard API endpoints
Expand Down
2 changes: 1 addition & 1 deletion enterprise_data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
Enterprise data api application. This Django app exposes API endpoints used by enterprises.
"""

__version__ = "9.2.0"
__version__ = "9.2.1"
33 changes: 21 additions & 12 deletions enterprise_data/api/v1/views/enterprise_learner.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from logging import getLogger
from uuid import UUID

from edx_django_utils.cache import TieredCache
from rest_framework import filters, viewsets
from rest_framework.decorators import action
from rest_framework.response import Response
Expand All @@ -18,12 +19,13 @@
from django.http import StreamingHttpResponse
from django.utils import timezone

from enterprise_data.admin_analytics.database.utils import LOGGER
from enterprise_data.api.v1 import serializers
from enterprise_data.filters import AuditEnrollmentsFilterBackend, AuditUsersEnrollmentFilterBackend
from enterprise_data.models import EnterpriseLearner, EnterpriseLearnerEnrollment
from enterprise_data.paginators import EnterpriseEnrollmentsPagination
from enterprise_data.renderers import EnrollmentsCSVRenderer
from enterprise_data.utils import subtract_one_month
from enterprise_data.utils import get_cache_key, subtract_one_month

from .base import EnterpriseViewSetMixin

Expand Down Expand Up @@ -82,19 +84,26 @@ def get_queryset(self):
enterprise_customer_uuid = self.kwargs['enterprise_id']

# TODO: Created a ticket ENT0-9531 to fix the cache issue
# Reason for Comenting cache: Remove the cache for this ViewSet
# becuae the cache is not working as expected
# cache_key = get_cache_key(
# resource='enterprise-learner',
# enterprise_customer=enterprise_customer_uuid,
# )
# cached_response = TieredCache.get_cached_response(cache_key)
# if cached_response.is_found:
# return cached_response.value
# else:
# Temporary logging to test cache issue
try:
LOGGER.info("Trying to get Learner Enrollment data from Cache")
cache_key = get_cache_key(
resource='enterprise-learner',
enterprise_customer=enterprise_customer_uuid,
)
cached_response = TieredCache.get_cached_response(cache_key)
if cached_response.is_found:
LOGGER.info("Learner Enrollment data found in Cache for Enterprise: [%s]", enterprise_customer_uuid)
else:
LOGGER.info("Learner Enrollment data not found in Cache for Enterprise: [%s]", enterprise_customer_uuid)
TieredCache.set_all_tiers(cache_key, 'dummy_enrollments', DEFAULT_LEARNER_CACHE_TIMEOUT)
LOGGER.info("Cache set for Enterprise: [%s] whose key is: [%s]", enterprise_customer_uuid, cache_key)
except Exception as e:
LOGGER.error("Memcached connection test failed: %s", e)

enrollments = EnterpriseLearnerEnrollment.objects.filter(enterprise_customer_uuid=enterprise_customer_uuid)
enrollments = self.apply_filters(enrollments)
# TieredCache.set_all_tiers(cache_key, enrollments, DEFAULT_LEARNER_CACHE_TIMEOUT)

return enrollments

def list(self, request, *args, **kwargs):
Expand Down

0 comments on commit 0157a52

Please sign in to comment.