perf(presence): 联系人列表与在线广播 presence 批量化(Redis pipeline 单次往返) - #2181
Merged
Conversation
Co-authored-by: Cursor <cursor@vectorcontrol.tech>
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Team Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
#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.Cacheport 扩展AreOnline;ListContacts循环前一次批量解析,循环内改查结果集。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全绿。备注