Commit 90a7cc17 by Calcium-Ion Committed by GitHub

Merge pull request #188 from Calcium-Ion/fix/many-model-error

fix: 修复渠道一次性添加很多model失败
parents 0d44e462 07724ce3
...@@ -3,6 +3,7 @@ package model ...@@ -3,6 +3,7 @@ package model
import ( import (
"errors" "errors"
"fmt" "fmt"
"github.com/samber/lo"
"gorm.io/gorm" "gorm.io/gorm"
"one-api/common" "one-api/common"
"strings" "strings"
...@@ -134,7 +135,16 @@ func (channel *Channel) AddAbilities() error { ...@@ -134,7 +135,16 @@ func (channel *Channel) AddAbilities() error {
abilities = append(abilities, ability) abilities = append(abilities, ability)
} }
} }
return DB.Create(&abilities).Error if len(abilities) == 0 {
return nil
}
for _, chunk := range lo.Chunk(abilities, 50) {
err := DB.Create(&chunk).Error
if err != nil {
return err
}
}
return nil
} }
func (channel *Channel) DeleteAbilities() error { func (channel *Channel) DeleteAbilities() error {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment