From 7376cd922144b7d4b65198e847ce0f9d07ad2fac Mon Sep 17 00:00:00 2001 From: Jaehun You Date: Mon, 2 Dec 2024 18:45:40 +0900 Subject: [PATCH] Use channel cache See also: #37 --- wlm_server/channel/serializer.py | 8 +++++--- wlm_server/channel/views.py | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/wlm_server/channel/serializer.py b/wlm_server/channel/serializer.py index 8ab8e36..e67a30c 100644 --- a/wlm_server/channel/serializer.py +++ b/wlm_server/channel/serializer.py @@ -1,3 +1,4 @@ +from django.conf import settings from rest_framework import serializers from operation.models import Operation @@ -15,9 +16,10 @@ class Meta: ) def get_in_use(self, obj: Channel): - user = self.context['user'] + operations = settings.CHANNEL_CACHE.get_operations(obj.channel) + username = self.context['username'] try: - operation = Operation.objects.filter(user=user, channel=obj).latest('occurred_at') - except Operation.DoesNotExist: + operation = operations[username] + except KeyError: return False return operation.on diff --git a/wlm_server/channel/views.py b/wlm_server/channel/views.py index 338bc5d..0131731 100644 --- a/wlm_server/channel/views.py +++ b/wlm_server/channel/views.py @@ -11,5 +11,5 @@ def handle_info(request): user = request.user channels = Channel.objects.filter(teams=user.team) - data = ChannelInfoSerializer(channels, many=True, context={'user': user}).data + data = ChannelInfoSerializer(channels, many=True, context={'username': user.username}).data return Response([dict_to_camel(info) for info in data])