MCPcopy Create free account
hub / github.com/aiprodcoder/MIXAPI / AddAbilities

Method AddAbilities

model/ability.go:181–215  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

179}
180
181func (channel *Channel) AddAbilities() error {
182 models_ := strings.Split(channel.Models, ",")
183 groups_ := strings.Split(channel.Group, ",")
184 abilitySet := make(map[string]struct{})
185 abilities := make([]Ability, 0, len(models_))
186 for _, model := range models_ {
187 for _, group := range groups_ {
188 key := group + "|" + model
189 if _, exists := abilitySet[key]; exists {
190 continue
191 }
192 abilitySet[key] = struct{}{}
193 ability := Ability{
194 Group: group,
195 Model: model,
196 ChannelId: channel.Id,
197 Enabled: channel.Status == common.ChannelStatusEnabled,
198 Priority: channel.Priority,
199 Weight: uint(channel.GetWeight()),
200 Tag: channel.Tag,
201 }
202 abilities = append(abilities, ability)
203 }
204 }
205 if len(abilities) == 0 {
206 return nil
207 }
208 for _, chunk := range lo.Chunk(abilities, 50) {
209 err := DB.Clauses(clause.OnConflict{DoNothing: true}).Create(&chunk).Error
210 if err != nil {
211 return err
212 }
213 }
214 return nil
215}
216
217func (channel *Channel) DeleteAbilities() error {
218 return DB.Where("channel_id = ?", channel.Id).Delete(&Ability{}).Error

Callers 3

InsertMethod · 0.95
BatchInsertChannelsFunction · 0.80
FixAbilityFunction · 0.80

Calls 1

GetWeightMethod · 0.95

Tested by

no test coverage detected