Skip to content

Commit

Permalink
remove lock logic from create & delete, which should be done by caller
Browse files Browse the repository at this point in the history
  • Loading branch information
calebx committed Dec 26, 2020
1 parent 5bdd7a3 commit b2426c9
Showing 1 changed file with 0 additions and 13 deletions.
13 changes: 0 additions & 13 deletions nested_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit b2426c9

Please sign in to comment.