Skip to content

perf(presence): 联系人列表与在线广播 presence 批量化(Redis pipeline 单次往返) - #2181

Merged
DeliciousBuding merged 1 commit into
masterfrom
chore/cleanup-round-36
Sep 1, 2026
Merged

perf(presence): 联系人列表与在线广播 presence 批量化(Redis pipeline 单次往返)#2181
DeliciousBuding merged 1 commit into
masterfrom
chore/cleanup-round-36

Conversation

@DeliciousBuding

Copy link
Copy Markdown
Collaborator

背景

#2154 探索 lane 新发现:联系人在线状态存在 Redis N+1。DB 侧 N+1 早已批量化(P2-1/P2-2 注释),但 presence 仍逐人一轮 HLEN device_route:<uid> 往返——ListContacts 每次拉联系人列表 = N 次 Redis RTT;broadcastOnlineStatus(上/下线事件扇出)同样逐好友查询。

变更

  • cache.Client.AreOnline(ctx, userIDs):把每人一条 HLEN 打包进单条 Redis pipeline(一次往返),入参去重,错误语义与逐项 IsOnline 一致(调用方忽略错误即视为离线)。
  • cache.NoOpCache.AreOnline 对齐。
  • contact.Cache port 扩展 AreOnlineListContacts 循环前一次批量解析,循环内改查结果集。
  • app.broadcastOnlineStatus:同样改为一次批量后再扇出。

验证

  • cache.TestAreOnline:空入参/混合在线离线/去重/路由删除翻转,miniredis 实测。
  • contact.TestListContacts_BatchesPresenceLookups:断言 AreOnline 恰好调用 1 次且覆盖全部好友、IsOnline 零调用,Online 标志逐人正确。
  • app.TestBroadcastOnlineStatusUsesBatchedPresence:sqlmock 好友列表 + miniredis 路由 + 真实 ws.Manager 连接——在线好友收到 device.online 帧,离线好友收不到。
  • go vet ./...make test(edge+hub)全绿;5 项 verifier + git diff --check 全绿。

备注

@coderabbitai

coderabbitai Bot commented Sep 1, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Team

Run ID: 0ee5a7ce-680e-4f1c-ab74-fb91baeefbd2

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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

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

@DeliciousBuding
DeliciousBuding merged commit c8f40bc into master Sep 1, 2026
39 checks passed
@DeliciousBuding
DeliciousBuding deleted the chore/cleanup-round-36 branch September 1, 2026 14:26
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