Merge pull request #4437 from seefs001/fix/channel-upstream-model-sync

fix(channel): load model mapping during upstream model checks
This commit is contained in:
Calcium-Ion
2026-04-26 20:17:14 +08:00
committed by GitHub
2 changed files with 26 additions and 2 deletions
+22 -2
View File
@@ -32,6 +32,26 @@ const (
channelUpstreamModelUpdateNotifyMaxFailedChannelIDs = 10
)
var channelUpstreamModelUpdateSelectFields = []string{
"id",
"name",
"type",
"key",
"status",
"base_url",
"models",
"model_mapping",
"settings",
"setting",
"other",
"group",
"priority",
"weight",
"tag",
"channel_info",
"header_override",
}
var (
channelUpstreamModelUpdateTaskOnce sync.Once
channelUpstreamModelUpdateTaskRunning atomic.Bool
@@ -521,7 +541,7 @@ func runChannelUpstreamModelUpdateTaskOnce() {
for {
var channels []*model.Channel
query := model.DB.
Select("id", "name", "type", "key", "status", "base_url", "models", "settings", "setting", "other", "group", "priority", "weight", "tag", "channel_info", "header_override").
Select(channelUpstreamModelUpdateSelectFields).
Where("status = ?", common.ChannelStatusEnabled).
Order("id asc").
Limit(channelUpstreamModelUpdateTaskBatchSize)
@@ -814,7 +834,7 @@ func collectPendingApplyUpstreamModelChanges(settings dto.ChannelOtherSettings)
func findEnabledChannelsAfterID(lastID int, batchSize int) ([]*model.Channel, error) {
var channels []*model.Channel
query := model.DB.
Select("id", "name", "type", "key", "status", "base_url", "models", "settings", "setting", "other", "group", "priority", "weight", "tag", "channel_info", "header_override").
Select(channelUpstreamModelUpdateSelectFields).
Where("status = ?", common.ChannelStatusEnabled).
Order("id asc").
Limit(batchSize)
@@ -81,6 +81,10 @@ func TestCollectPendingApplyUpstreamModelChanges(t *testing.T) {
require.Equal(t, []string{"old-model"}, pendingRemoveModels)
}
func TestChannelUpstreamModelUpdateSelectFieldsIncludeModelMapping(t *testing.T) {
require.Contains(t, channelUpstreamModelUpdateSelectFields, "model_mapping")
}
func TestNormalizeChannelModelMapping(t *testing.T) {
modelMapping := `{
" alias-model ": " upstream-model ",