From 3457eff339146bc589a00a4b52afe8863dabd5e1 Mon Sep 17 00:00:00 2001 From: cuom1999 Date: Sat, 13 Jan 2024 18:40:10 -0600 Subject: [PATCH] Clean up more lock DB --- judge/comments.py | 1 - judge/views/bookmark.py | 1 - judge/views/comment.py | 22 +++++++++------------- 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/judge/comments.py b/judge/comments.py index 58fdcd1..3869194 100644 --- a/judge/comments.py +++ b/judge/comments.py @@ -23,7 +23,6 @@ from reversion import revisions from reversion.models import Revision, Version from django_ratelimit.decorators import ratelimit -from judge.dblock import LockModel from judge.models import Comment, Notification from judge.widgets import HeavyPreviewPageDownWidget from judge.jinja2.reference import get_user_from_text diff --git a/judge/views/bookmark.py b/judge/views/bookmark.py index 3f4224b..7f31c1f 100644 --- a/judge/views/bookmark.py +++ b/judge/views/bookmark.py @@ -12,7 +12,6 @@ from judge.models.bookmark import BookMark, MakeBookMark from django.views.generic.base import TemplateResponseMixin from django.views.generic.detail import SingleObjectMixin -from judge.dblock import LockModel from django.views.generic import View, ListView diff --git a/judge/views/comment.py b/judge/views/comment.py index cfe9adf..9e5a986 100644 --- a/judge/views/comment.py +++ b/judge/views/comment.py @@ -25,7 +25,6 @@ from reversion.models import Version from django.conf import settings from django_ratelimit.decorators import ratelimit -from judge.dblock import LockModel from judge.models import Comment, CommentVote, Notification, BlogPost from judge.utils.views import TitleMixin from judge.widgets import MathJaxPagedownWidget, HeavyPreviewPageDownWidget @@ -83,18 +82,15 @@ def vote_comment(request, delta): try: vote.save() except IntegrityError: - with LockModel(write=(CommentVote,)): - try: - vote = CommentVote.objects.get( - comment_id=comment_id, voter=request.profile - ) - except CommentVote.DoesNotExist: - raise Http404() - if -vote.score != delta: - return HttpResponseBadRequest( - _("You already voted."), content_type="text/plain" - ) - vote.delete() + try: + vote = CommentVote.objects.get(comment_id=comment_id, voter=request.profile) + except CommentVote.DoesNotExist: + raise Http404() + if -vote.score != delta: + return HttpResponseBadRequest( + _("You already voted."), content_type="text/plain" + ) + vote.delete() Comment.objects.filter(id=comment_id).update(score=F("score") - vote.score) else: Comment.objects.filter(id=comment_id).update(score=F("score") + delta)