fix: channel cache fail-close, group conflict check across pages, status toggle stale data
- GetGroupPlatforms failure now stores error-TTL cache and returns error (fail-close) - Frontend group-to-channel conflict map loads all channels instead of current page only - Toggle channel status reloads list when active filter would hide the changed item
This commit is contained in:
@@ -188,7 +188,7 @@ func (r *channelRepository) List(ctx context.Context, params pagination.Paginati
|
||||
// 查询 channel 列表
|
||||
dataQuery := fmt.Sprintf(
|
||||
`SELECT c.id, c.name, c.description, c.status, c.model_mapping, c.billing_model_source, c.restrict_models, c.created_at, c.updated_at
|
||||
FROM channels c WHERE %s ORDER BY c.id DESC LIMIT $%d OFFSET $%d`,
|
||||
FROM channels c WHERE %s ORDER BY c.id ASC LIMIT $%d OFFSET $%d`,
|
||||
whereClause, argIdx, argIdx+1,
|
||||
)
|
||||
args = append(args, pageSize, offset)
|
||||
|
||||
@@ -278,7 +278,10 @@ func (s *ChannelService) buildCache(ctx context.Context) (*channelCache, error)
|
||||
groupPlatforms, err = s.repo.GetGroupPlatforms(dbCtx, allGroupIDs)
|
||||
if err != nil {
|
||||
slog.Warn("failed to load group platforms for channel cache", "error", err)
|
||||
// 降级:继续构建缓存但无法按平台过滤
|
||||
errorCache := newEmptyChannelCache()
|
||||
errorCache.loadedAt = time.Now().Add(-(channelCacheTTL - channelErrorTTL))
|
||||
s.cache.Store(errorCache)
|
||||
return nil, fmt.Errorf("get group platforms: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1182,12 +1182,15 @@ func TestBuildCache_GroupPlatformError(t *testing.T) {
|
||||
}
|
||||
svc := newTestChannelService(repo)
|
||||
|
||||
// Should degrade gracefully: channel is found, but without platform info
|
||||
// pricing won't match because platform will be "" and pricing platform is "anthropic"
|
||||
// Should fail-close: error propagated when group platforms cannot be loaded
|
||||
result, err := svc.GetChannelForGroup(context.Background(), 10)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, result) // channel still found
|
||||
require.Equal(t, int64(1), result.ID)
|
||||
require.Error(t, err)
|
||||
require.Nil(t, result)
|
||||
|
||||
// Within error-TTL, second call should hit cache (empty) and return nil, nil
|
||||
result2, err2 := svc.GetChannelForGroup(context.Background(), 10)
|
||||
require.NoError(t, err2)
|
||||
require.Nil(t, result2)
|
||||
}
|
||||
|
||||
func TestBuildCache_MultipleGroupsSameChannel(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user