Skip to content

Commit

Permalink
fix: optimize performance for loop in UpdateFilteredPolicies() (#185)
Browse files Browse the repository at this point in the history
  • Loading branch information
hanshengzhao authored Oct 19, 2022
1 parent 198ef24 commit 87dd6fe
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -835,17 +835,16 @@ func (a *Adapter) UpdateFilteredPolicies(sec string, ptype string, newPolicies [
}

tx := a.db.Begin()

str, args := line.queryString()
if err := tx.Where(str, args...).Find(&oldP).Error; err != nil {
tx.Rollback()
return nil, err
}
if err := tx.Where(str, args...).Delete([]CasbinRule{}).Error; err != nil {
tx.Rollback()
return nil, err
}
for i := range newP {
str, args := line.queryString()
if err := tx.Where(str, args...).Find(&oldP).Error; err != nil {
tx.Rollback()
return nil, err
}
if err := tx.Where(str, args...).Delete([]CasbinRule{}).Error; err != nil {
tx.Rollback()
return nil, err
}
if err := tx.Create(&newP[i]).Error; err != nil {
tx.Rollback()
return nil, err
Expand Down

0 comments on commit 87dd6fe

Please sign in to comment.