Skip to content

飞书群列表按群补读并断点续读,inbox.collect 复用未变的结果 - #69

Open
NginxL wants to merge 1 commit into
mainfrom
perf/feishu-groups-inbox
Open

NginxL wants to merge 1 commit into
mainfrom
perf/feishu-groups-inbox

Conversation

@NginxL

@NginxL NginxL commented Dec 6, 2026

Copy link
Copy Markdown
Owner

做了什么

只读排查线上 m-06a702(飞书扩展 0.11.83)发现四个性能问题,这个 PR 一起处理:

  1. 群列表整表重读风暴(larkagentx.py)
    • 原因:任何不在群表里的群来一条推送,就整表重读一次。账号有 3,761 个群,整表读约 114 个请求,任何一页失败都要等 60 秒从头再来。
    • 线上实测:每天整表读 87–765 次,按设计应不超过 24 次;失败 11–457 次。
    • 现在:
      • 未知群只补读那一个群,读不到的群 6 小时内不再问。
      • 整表读失败后从断点续读,退避时间从 60 秒逐步加到 15 分钟。
      • 详情只拉新增的群。
      • 整表读改为每 6 小时一次。
  2. inbox.collect 每次全量重算(core/openmate_core/app.py)
    • 原因:每次都对 3 天内活跃的会话逐个读 60–300 行。
    • 线上实测:7 天 4.7 万次调用,大多 100–500 ms。
    • 现在:
      • 没有变化就直接复用上次的结果。
      • 只重算会话版本、头像或免打扰变过的会话。
      • 读行改用 inbox_rows_many,分两批取。
  3. 冗余索引(store.py):删掉 messages_chat_root,它是 messages_chat_root_pos 的前缀。
  4. 今日卡片(today.py):调用 Persona 的那一段给 1.5 秒预算,超时就沿用上次成功的结果,并标出数据时间,不再拖住页面。

怎么验证的

  • 每项都补了测试,并确认新测试在旧代码上会失败。
  • bash scripts/test.sh 三组全部通过:983、425(跳过 2)、191。打包校验目前只提示需要升版本号,合入时再处理。
  • 第一版有一个头像刷新回归:缓存复用时没核对头像的检查时间。全量测试抓到后已经修掉,并补了测试。
  • 用 23,160 条合成消息对比,飞书和微信的 inbox.collect 输出都与旧实现一致。

没做什么

  • 消息保留期不变,messages 仍然只增不减。要不要加保留期是产品决定,另说。
  • 版本号和发布包没动,审查通过后按 AGENTS.md 的流程处理。改了 core/,两个扩展都要升。

🤖 Generated with Claude Code

…; inbox.collect reuses unchanged results

- larkagentx: a push from an unknown group fetches only that chat (negative cache for GROUPS_EVERY); the whole
  group read resumes from the failed page with 60 s → 15 min backoff, fetches details only for new ids, and runs
  every 6 h. Live it ran 87–765 times a day (≤ 24 expected), ~114 requests each, 11–457 failures a day.
- core inbox.collect: reuses the whole result when nothing changed and recomputes only chats whose versions,
  avatars or mutes changed, reading rows with inbox_rows_many in two batches (was 100–500 ms per call, 47k
  calls a week). WeChat output unchanged (checked against 23,160 synthetic messages).
- store: drops the redundant messages_chat_root index (a prefix of messages_chat_root_pos).
- today card: the Persona part gets a 1.5 s budget and falls back to the last good value, marked with its time.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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