Skip to content

Commit

Permalink
Use channel cache
Browse files Browse the repository at this point in the history
See also: #37
  • Loading branch information
BECATRUE committed Dec 2, 2024
1 parent 5b73a66 commit 7376cd9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions wlm_server/channel/serializer.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.conf import settings
from rest_framework import serializers

from operation.models import Operation
Expand All @@ -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
2 changes: 1 addition & 1 deletion wlm_server/channel/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])

0 comments on commit 7376cd9

Please sign in to comment.