Skip to content

Conversation

momomobinx
Copy link

@momomobinx momomobinx commented Sep 4, 2025

…MultiKeyPollingIndex 需要继承否则会导致轮询索引重置,影响多key轮询的正确性

Summary by CodeRabbit

  • Bug Fixes
    • Preserves multi-key polling progress across cache refreshes, preventing index resets that could cause redundant requests, delays, or missed cycles.
    • Improves continuity and stability of polling during channel cache rebuilds, leading to more consistent behavior under key rotation or background refreshes.
    • Reduces transient interruptions and improves responsiveness for workloads relying on multi-key polling.

…MultiKeyPollingIndex 需要继承

	// 否则会导致轮询索引重置,影响多key轮询的正确性
Copy link
Contributor

coderabbitai bot commented Sep 4, 2025

Walkthrough

A loop was added in InitChannelCache to copy ChannelInfo.MultiKeyPollingIndex from existing cached channels to newly built cache entries by matching IDs. This preserves the polling index state across cache refreshes without changing public interfaces.

Changes

Cohort / File(s) Summary of edits
Channel cache refresh logic
model/channel_cache.go
After constructing newChannelId2channel and newGroup2model2channels, added a pass that, for matching channel IDs, copies ChannelInfo.MultiKeyPollingIndex from the old cache (channelsIDM) into the new cache to retain multi-key polling position across refreshes.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Caller
  participant Cache as ChannelCache
  participant Store as BackendStore

  Caller->>Cache: InitChannelCache()
  Cache->>Store: Load channels/groups
  Store-->>Cache: newChannelId2channel, newGroup2model2channels
  rect rgb(235, 245, 255)
    note over Cache: Preserve polling index
    Cache->>Cache: For each channelID in new cache
    Cache->>Cache: If channelID exists in old cache<br/>copy MultiKeyPollingIndex
  end
  Cache-->>Caller: Updated cache with preserved indices
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

Thump-thump, my paws cache-hop with glee,
I saved the index—one, two, three!
No reset storms, just steady flow,
Keys keep polling, to and fro.
In burrows of bytes I softly cheer:
“State preserved! The path stays clear.” 🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 91a627d and 44e1d12.

📒 Files selected for processing (1)
  • model/channel_cache.go (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
model/channel_cache.go (1)
model/channel.go (1)
  • ChannelInfo (51-57)

@seefs001
Copy link
Collaborator

seefs001 commented Sep 7, 2025

缓存开启时轮训key,数据库index不会更新,这些都在缓存里运作的,不需要从数据库里去读取状态

@seefs001 seefs001 closed this Sep 7, 2025
@momomobinx
Copy link
Author

缓存开启时轮训key,数据库index不会更新,这些都在缓存里运作的,不需要从数据库里去读取状态

是有个定时任务,定时从数据库同步到缓存,然后将缓存的index 覆盖成了0,倒是轮询的时候,本来轮询到5,然后同步后立马跳回0,导致前几个key使用最为频繁,我看到key好像是一分钟同步一次,同步后就算后面还有很多的key也是继续从0开始。然后改动的逻辑是从数据库同步的时候,只是将老的index继续存在缓存延续

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.

2 participants