From ddcd4ebbfc692c4e3baab2a4b17182dee4ba4a56 Mon Sep 17 00:00:00 2001 From: Bai Date: Tue, 14 Jul 2020 19:02:23 +0800 Subject: [PATCH] =?UTF-8?q?fix(asset=5Fuser):=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E5=88=9B=E5=BB=BAAuthBook=E5=AF=B9=E8=B1=A1=E9=94=81=E6=9C=BA?= =?UTF-8?q?=E5=88=B6=EF=BC=8C=E4=BD=BF=E7=94=A8select=5Ffor=5Fupdate?= =?UTF-8?q?=E6=9B=BF=E6=8D=A2redis=5Flock3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/assets/models/authbook.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/apps/assets/models/authbook.py b/apps/assets/models/authbook.py index 87e96c3fe..7d0a3f472 100644 --- a/apps/assets/models/authbook.py +++ b/apps/assets/models/authbook.py @@ -59,10 +59,9 @@ class AuthBook(BaseUser): username = kwargs['username'] asset = kwargs['asset'] with transaction.atomic(): - # 使用select_for_update限制并发创建相同的username、asset数据 - cls.objects.select_for_update().filter( - username=username, asset=asset, is_latest=True - ).update(is_latest=False) + # 使用select_for_update限制并发创建相同的username、asset条目 + instances = cls.objects.select_for_update().filter(username=username, asset=asset) + instances.filter(is_latest=True).update(is_latest=False) max_version = cls.get_max_version(username, asset) kwargs.update({ 'version': max_version + 1,