Skip to content
Open
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
23 changes: 23 additions & 0 deletions t22.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from rest_framework.response import Response
from rest_framework.viewsets import ViewSet

from common_utils.api.permissions import IsAccountContext

from metrics.cache import MetricsCache
from metrics.services import calculate_metrics


class MetricsViewSet(ViewSet):
schema_tag = 'Metrics'
permission_classes = (IsAccountContext,)

def list(self, request, *args, **kwargs):
account = self.request.auth.account
cached_response = MetricsCache.get_metrics(account.id)

if cached_response:
return Response(cached_response)

data = calculate_metrics(account)
MetricsCache.set_metrics(account.id, data)
return Response(data)