Clean up more lock DB

This commit is contained in:
cuom1999 2024-01-13 18:40:10 -06:00
parent ad73e4cdf3
commit 3457eff339
3 changed files with 9 additions and 15 deletions

View file

@ -23,7 +23,6 @@ from reversion import revisions
from reversion.models import Revision, Version from reversion.models import Revision, Version
from django_ratelimit.decorators import ratelimit from django_ratelimit.decorators import ratelimit
from judge.dblock import LockModel
from judge.models import Comment, Notification from judge.models import Comment, Notification
from judge.widgets import HeavyPreviewPageDownWidget from judge.widgets import HeavyPreviewPageDownWidget
from judge.jinja2.reference import get_user_from_text from judge.jinja2.reference import get_user_from_text

View file

@ -12,7 +12,6 @@ from judge.models.bookmark import BookMark, MakeBookMark
from django.views.generic.base import TemplateResponseMixin from django.views.generic.base import TemplateResponseMixin
from django.views.generic.detail import SingleObjectMixin from django.views.generic.detail import SingleObjectMixin
from judge.dblock import LockModel
from django.views.generic import View, ListView from django.views.generic import View, ListView

View file

@ -25,7 +25,6 @@ from reversion.models import Version
from django.conf import settings from django.conf import settings
from django_ratelimit.decorators import ratelimit from django_ratelimit.decorators import ratelimit
from judge.dblock import LockModel
from judge.models import Comment, CommentVote, Notification, BlogPost from judge.models import Comment, CommentVote, Notification, BlogPost
from judge.utils.views import TitleMixin from judge.utils.views import TitleMixin
from judge.widgets import MathJaxPagedownWidget, HeavyPreviewPageDownWidget from judge.widgets import MathJaxPagedownWidget, HeavyPreviewPageDownWidget
@ -83,18 +82,15 @@ def vote_comment(request, delta):
try: try:
vote.save() vote.save()
except IntegrityError: except IntegrityError:
with LockModel(write=(CommentVote,)): try:
try: vote = CommentVote.objects.get(comment_id=comment_id, voter=request.profile)
vote = CommentVote.objects.get( except CommentVote.DoesNotExist:
comment_id=comment_id, voter=request.profile raise Http404()
) if -vote.score != delta:
except CommentVote.DoesNotExist: return HttpResponseBadRequest(
raise Http404() _("You already voted."), content_type="text/plain"
if -vote.score != delta: )
return HttpResponseBadRequest( vote.delete()
_("You already voted."), content_type="text/plain"
)
vote.delete()
Comment.objects.filter(id=comment_id).update(score=F("score") - vote.score) Comment.objects.filter(id=comment_id).update(score=F("score") - vote.score)
else: else:
Comment.objects.filter(id=comment_id).update(score=F("score") + delta) Comment.objects.filter(id=comment_id).update(score=F("score") + delta)