From 3e614c38e427fea52a695b8e50fbe8419a9b9c21 Mon Sep 17 00:00:00 2001 From: NoahLan <6995syu@163.com> Date: Tue, 20 Jun 2023 10:30:29 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Dopt=5Flock=E5=BC=95?= =?UTF-8?q?=E5=85=A5=E7=AC=AC=E4=B8=89=E6=96=B9=E5=8C=85=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=EF=BC=8C=E6=97=A0=E9=9C=80=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/orm/nent/mixins/optimistic_lock.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/core/orm/nent/mixins/optimistic_lock.go b/core/orm/nent/mixins/optimistic_lock.go index 7f8d8bd..fc8e9a5 100644 --- a/core/orm/nent/mixins/optimistic_lock.go +++ b/core/orm/nent/mixins/optimistic_lock.go @@ -7,7 +7,6 @@ import ( "entgo.io/ent/schema/field" "entgo.io/ent/schema/mixin" "fmt" - "github.com/casbin/ent-adapter/ent/hook" ) // OptimisticLockMixin implements the ent.Mixin for sharing @@ -34,9 +33,9 @@ func WithVersion(parent context.Context, version int64) context.Context { // Hooks of the OptimisticLockMixin. func (d OptimisticLockMixin) Hooks() []ent.Hook { return []ent.Hook{ - hook.On( - func(next ent.Mutator) ent.Mutator { - return ent.MutateFunc(func(ctx context.Context, m ent.Mutation) (ent.Value, error) { + func(next ent.Mutator) ent.Mutator { + return ent.MutateFunc(func(ctx context.Context, m ent.Mutation) (ent.Value, error) { + if m.Op().Is(ent.OpUpdate | ent.OpUpdateOne) { mx, ok := m.(interface { AddVersion(i int64) WhereP(...func(*sql.Selector)) @@ -52,10 +51,10 @@ func (d OptimisticLockMixin) Hooks() []ent.Hook { // set version=version+1 mx.AddVersion(1) return next.Mutate(ctx, m) - }) - }, - ent.OpUpdate|ent.OpUpdateOne, - ), + } + return next.Mutate(ctx, m) + }) + }, } }