From b2426c96ba52151122f366c32b52afea04fe4e42 Mon Sep 17 00:00:00 2001 From: "caleb.xiang" Date: Sat, 26 Dec 2020 10:28:08 +0800 Subject: [PATCH] remove lock logic from create & delete, which should be done by caller --- nested_set.go | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/nested_set.go b/nested_set.go index 0537371..a6c0ad1 100644 --- a/nested_set.go +++ b/nested_set.go @@ -103,13 +103,6 @@ func parseNode(db *gorm.DB, source interface{}) (tx *gorm.DB, item nodeItem, err // ```nestedset.Create(db, &Category{...}, &parent)``` will create a new category under parent node as its last child func Create(db *gorm.DB, source, parent interface{}) error { return db.Transaction(func(db *gorm.DB) (err error) { - // lock table - lockRst := make(map[string]interface{}, 0) - err = db.Model(source).Clauses(clause.Locking{Strength: "UPDATE"}).Find(&lockRst).Error - if err != nil { - return nil - } - tx, target, err := parseNode(db, source) if err != nil { return err @@ -196,12 +189,6 @@ func Create(db *gorm.DB, source, parent interface{}) error { // ```nestedset.Delete(db, &Category{...})``` func Delete(db *gorm.DB, source interface{}) error { return db.Transaction(func(db *gorm.DB) (err error) { - // lock table - err = db.Model(source).Clauses(clause.Locking{Strength: "UPDATE"}).Find(source).Error - if err != nil { - return nil - } - // load node from locked DB to avoid override rst := db.First(source) if rst.Error != nil {