perf(customers): message 补 (channel,owner,timestamp) 索引,列表 7.6s→0.03s
客户列表行内「今日收发」聚合按 channel=?+owner IN+timestamp>= GROUP BY, 两个既有索引把 timestamp 排在 talker/room 后无法 seek——asyncmy 服务端 预编译时优化器弃索引全表扫 86 万含大文本宽行,实测 7.7s/次,前端每次翻页 都撞(用户报微信客户列表加载慢)。补三列窄索引后 owner 前缀直接落入当天 几百行:GROUP BY 0.14s、API 全链 0.032s(78 倍,翻页/WA/员工过滤同测)。 模型+迁移同步声明(防 autogenerate 反向 DROP),inspect 幂等。 Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -429,6 +429,18 @@ class Message(Base):
|
||||
"room_id",
|
||||
"timestamp",
|
||||
),
|
||||
# 今日收发聚合热路径:channel= + owner IN + timestamp>= 定位当天消息
|
||||
# (customer 列表行内 send_today/receive_today)。上面两个索引把
|
||||
# timestamp 排在 talker/room 之后,时间范围无法直接 seek;MySQL 预编译
|
||||
# 语句(asyncmy 走服务端 prepare)优化器弃索引转全表扫 86 万含大文本
|
||||
# 的行,实测 7.7s/次(2026-08-27),裸字面量也要 0.23s 扫 92 万索引项。
|
||||
# 此索引让 (channel, owner) 前缀下按 timestamp 直接落入当天几百行。
|
||||
Index(
|
||||
"ix_message_channel_owner_time",
|
||||
"channel",
|
||||
"owner_account_id",
|
||||
"timestamp",
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user