Skip to content

Commit

Permalink
feat: use transaction atomic when creating msgs
Browse files Browse the repository at this point in the history
  • Loading branch information
helllllllder committed Oct 15, 2024
1 parent 6b745ca commit 1e87a80
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions chats/apps/api/v1/msgs/viewsets.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.db import transaction
from django_filters.rest_framework import DjangoFilterBackend
from pydub.exceptions import CouldntDecodeError
from rest_framework import filters, mixins, pagination, parsers, status, viewsets
Expand Down Expand Up @@ -40,8 +41,9 @@ def create(self, request, *args, **kwargs):
return super().create(request, *args, **kwargs)

def perform_create(self, serializer):
serializer.save()
serializer.instance.notify_room("create", True)
with transaction.atomic():
serializer.save()
serializer.instance.notify_room("create", True)

def perform_update(self, serializer):
serializer.save()
Expand Down Expand Up @@ -106,7 +108,8 @@ def create(self, request, *args, **kwargs):
)

def perform_create(self, serializer):
serializer.save()
instance = serializer.instance
instance.message.notify_room("update")
instance.callback()
with transaction.atomic():
serializer.save()
instance = serializer.instance
instance.message.notify_room("update")
instance.callback()

0 comments on commit 1e87a80

Please sign in to comment.