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

Method Update

model/channel.go:410–457  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

408}
409
410func (channel *Channel) Update() error {
411 // If this is a multi-key channel, recalculate MultiKeySize based on the current key list to avoid inconsistency after editing keys
412 if channel.ChannelInfo.IsMultiKey {
413 var keyStr string
414 if channel.Key != "" {
415 keyStr = channel.Key
416 } else {
417 // If key is not provided, read the existing key from the database
418 if existing, err := GetChannelById(channel.Id, true); err == nil {
419 keyStr = existing.Key
420 }
421 }
422 // Parse the key list (supports newline separation or JSON array)
423 keys := []string{}
424 if keyStr != "" {
425 trimmed := strings.TrimSpace(keyStr)
426 if strings.HasPrefix(trimmed, "[") {
427 var arr []json.RawMessage
428 if err := json.Unmarshal([]byte(trimmed), &arr); err == nil {
429 keys = make([]string, len(arr))
430 for i, v := range arr {
431 keys[i] = string(v)
432 }
433 }
434 }
435 if len(keys) == 0 { // fallback to newline split
436 keys = strings.Split(strings.Trim(keyStr, "\n"), "\n")
437 }
438 }
439 channel.ChannelInfo.MultiKeySize = len(keys)
440 // Clean up status data that exceeds the new key count to prevent index out of range
441 if channel.ChannelInfo.MultiKeyStatusList != nil {
442 for idx := range channel.ChannelInfo.MultiKeyStatusList {
443 if idx >= channel.ChannelInfo.MultiKeySize {
444 delete(channel.ChannelInfo.MultiKeyStatusList, idx)
445 }
446 }
447 }
448 }
449 var err error
450 err = DB.Model(channel).Updates(channel).Error
451 if err != nil {
452 return err
453 }
454 DB.Model(channel).First(channel, "id = ?", channel.Id)
455 err = channel.UpdateAbilities(nil)
456 return err
457}
458
459func (channel *Channel) UpdateResponseTime(responseTime int64) {
460 err := DB.Model(channel).Select("response_time", "test_time").Updates(Channel{

Callers 5

SaveChannelInfoMethod · 0.45
EnableChannelByTagFunction · 0.45
DisableChannelByTagFunction · 0.45
updateChannelUsedQuotaFunction · 0.45
BatchSetChannelTagFunction · 0.45

Calls 2

UpdateAbilitiesMethod · 0.95
GetChannelByIdFunction · 0.85

Tested by

no test coverage detected