Skip to content

Conversation

@longkeyy
Copy link
Contributor

功能改进:

  1. 修复 InitChannelCache() 基于 abilities 表构建准确缓存
  2. 添加缓存失效函数 (InvalidateChannelCache, InvalidateGroupModelCache, InvalidateUserCache)
  3. 修复 UpdateChannelStatusById() 立即同步缓存
  4. 修复 Channel.Update() 配置变更时的缓存同步
  5. 添加全面的缓存测试

- Fix InitChannelCache to use abilities table for accurate cache building
- Add cache invalidation functions (InvalidateChannelCache, InvalidateGroupModelCache, InvalidateUserCache)
- Update UpdateChannelStatusById to immediately invalidate related caches
- Update Channel.Update() to invalidate caches when configuration changes
- Add comprehensive cache tests
- Ensure real-time cache sync for channel status changes

This fixes the issue where channel status changes (enable/disable)
required service restart to take effect.
Copilot AI review requested due to automatic review settings August 26, 2025 18:48
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR improves the cache synchronization mechanism by fixing several cache consistency issues. The changes ensure that cache state remains accurate when channel configurations are modified and provide more granular cache invalidation capabilities.

  • Fixed InitChannelCache() to build cache based on abilities table for accuracy
  • Added cache invalidation functions for immediate synchronization after updates
  • Enhanced channel status and configuration update methods with proper cache invalidation

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
model/channel.go Enhanced Channel.Update() and UpdateChannelStatusById() with cache invalidation logic
model/cache.go Refactored cache initialization and added invalidation functions
model/cache_test.go Added comprehensive test suite for cache functionality

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +154 to +156
if err != nil {
return err
}
Copy link

Copilot AI Aug 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing conditional check for UpdateAbilities() error. The error variable err is assigned but there's no if err != nil check before line 154.

Copilot uses AI. Check for mistakes.
Comment on lines 177 to 181
newChannelId2channel := make(map[int]*Channel)
var channels []*Channel
DB.Where("status = ?", ChannelStatusEnabled).Find(&channels)
for _, channel := range channels {
newChannelId2channel[channel.Id] = channel
Copy link

Copilot AI Aug 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable newChannelId2channel is created but never used in the updated InitChannelCache() function. This appears to be leftover code from the refactoring.

Suggested change
newChannelId2channel := make(map[int]*Channel)
var channels []*Channel
DB.Where("status = ?", ChannelStatusEnabled).Find(&channels)
for _, channel := range channels {
newChannelId2channel[channel.Id] = channel
var channels []*Channel
DB.Where("status = ?", ChannelStatusEnabled).Find(&channels)
for _, channel := range channels {
// no longer populating newChannelId2channel

Copilot uses AI. Check for mistakes.
Comment on lines +52 to +58
channels := []*Channel{
{
Id: 1,
Status: ChannelStatusEnabled,
Group: "default",
Models: "gpt-3.5-turbo",
Priority: &[]int64{0}[0],
Copy link

Copilot AI Aug 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This inline slice creation and dereferencing pattern &[]int64{0}[0] is unnecessarily complex. Consider using a helper variable: priority := int64(0); Priority: &priority,

Suggested change
channels := []*Channel{
{
Id: 1,
Status: ChannelStatusEnabled,
Group: "default",
Models: "gpt-3.5-turbo",
Priority: &[]int64{0}[0],
priority := int64(0)
channels := []*Channel{
{
Id: 1,
Status: ChannelStatusEnabled,
Group: "default",
Models: "gpt-3.5-turbo",
Priority: &priority,

Copilot uses AI. Check for mistakes.
iceyarmu pushed a commit to iceyarmu/one-api that referenced this pull request Dec 3, 2025
…ance-playground-debugging

feat(playground): enhance SSE debugging and add image paste support with i18n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant