chore: record session journal - 握力环训练趣味化

This commit is contained in:
2026-05-27 16:53:33 +08:00
parent 261f8315de
commit b9d2541b32
946 changed files with 107438 additions and 0 deletions
@@ -0,0 +1 @@
{"file":".trellis/tasks/05-07-conversion-overview-mysql8/research/current-findings.md","reason":"Use the documented MySQL 8 compatibility risks and log evidence to review only the relevant SQL paths in ConversionLogic.php."}
@@ -0,0 +1 @@
{"file":".trellis/tasks/05-07-conversion-overview-mysql8/research/current-findings.md","reason":"Summarizes the actual MySQL 8 log error and the current risk points inside ConversionLogic.php so the implement agent can focus on the likely incompatible SQL paths."}
@@ -0,0 +1,57 @@
# conversion overview mysql8 compatibility
## Goal
修复 `adminapi/stats.conversion/overview` 在数据库切换到 MySQL 8.0 后的 SQL 不兼容问题,并在不引入缓存的前提下优化该方法中的慢查询,保证 `dimension=dept``include_filters=1` 场景可正常且更快地查询。
## What I already know
* 主逻辑在 `server/app/adminapi/logic/stats/ConversionLogic.php`
* 运行日志里已有一条 MySQL 语法错误记录:
`SQLSTATE[42000]: Syntax error or access violation: 1064 ... near '( q.follow_admin_ids, '$[*]' COLUMNS (...)'`
* 当前 `ConversionLogic.php` 已不再包含 `JSON_TABLE`,说明兼容修复可能做过一半,仍需核对当前文件中的 MySQL 8 风险点
* 当前文件仍有多处 `fieldRaw + group` 聚合查询,MySQL 8 默认 `ONLY_FULL_GROUP_BY` 更严格,需要重点检查
* 当前文件使用了表名 `order``whereRaw`、多处左连接与聚合,均可能触发 MySQL 8 兼容性问题
* 历史运行日志显示慢点主要集中在:
* `hydrateFanStats`,多次达到 `0.7s ~ 2.4s`
* `include_filters=1` 时的 `buildFilterOptions -> DiagnosisLogic::getAssistants`,曾到 `18s+`
## Assumptions (temporary)
* 当前用户提到的“不兼容”针对的是 `stats.conversion/overview` 当前版本,不要求顺带修复其他统计模块
* 优先修复服务端 SQL 兼容性,并优化 SQL 结构,不改接口出参结构
* 若发现旧版遗留的 JSON_TABLE 逻辑已被替换,则以当前代码中的聚合、NULL 比较、保留字、原生 SQL 片段为修复重点
## Open Questions
* 无。已有日志和代码足够开始修复。
## Requirements
* 审查并修复 `ConversionLogic.php` 中 MySQL 8.0 不兼容 SQL
* 保证 `overview?page_no=1&page_size=15&dimension=dept&media_channel_code=&time_type=today&include_filters=1` 可执行
* 优化该接口中的主要慢 SQL,重点关注 `hydrateFanStats``include_filters=1` 时的筛选项查询
* 避免引入新的统计口径变化
* 尽量将原生 SQL 改为更稳定的 Builder 写法,或改成 MySQL 8 兼容表达式
## Acceptance Criteria
* [ ] `ConversionLogic` 中不再包含已知 MySQL 8 不兼容写法
* [ ] 关键聚合查询在 MySQL 8 的 `ONLY_FULL_GROUP_BY` 下可通过
* [ ] 至少一个已知慢点的 SQL 结构得到收敛优化
* [ ] 不改变现有接口结构和主要业务语义
* [ ] 至少完成 PHP 语法检查
## Out of Scope
* 其他统计模块(如 `YejiStatsLogic``DoctorDailyStatsLogic`)的整体兼容性修复
* 前端页面样式或交互修改
## Technical Notes
* 目标文件:`server/app/adminapi/logic/stats/ConversionLogic.php`
* 参考日志:`server/runtime/adminapi/log/202604/22.log`
## Research References
* [`research/current-findings.md`](research/current-findings.md) — 当前代码与历史报错线索
@@ -0,0 +1,35 @@
# 当前排查结论
## 已确认事实
* `stats.conversion/overview` 的主实现位于 `server/app/adminapi/logic/stats/ConversionLogic.php`
* 历史日志 `server/runtime/adminapi/log/202604/22.log` 中存在 MySQL 1064
`near '( q.follow_admin_ids, '$[*]' COLUMNS (...)'`
* 当前 `ConversionLogic.php` 中已经搜索不到 `JSON_TABLE`,说明旧问题可能已被部分替换
## 当前文件中的 MySQL 8 风险点
* 多处 `fieldRaw(...) + group(...)` 聚合
* 多处 `whereRaw(...)`
* 使用保留字表名 `order`
* `include_filters=1` 会额外触发筛选项构建,可能带出更多 SQL 路径
## 已观察到的性能热点
* `server/runtime/adminapi/log/202604/22.log` 中:
* `hydrateFanStats cost` 多次达到 `0.7s ~ 2.4s`
* `hydrateAppointmentStats` / `hydrateOrderAndAmountStats` 通常约 `0.08s ~ 0.13s`
* `include_filters=1``buildFilterOptions -> DiagnosisLogic::getAssistants` 曾达到 `18s+`
* 因此本次 SQL 优化应优先关注:
* `ConversionLogic::hydrateFanStats()`
* `ConversionLogic::buildFilterOptions()` 触发的医助筛选项路径
## 本次修复策略
*`ConversionLogic.php` 为主;若 `include_filters=1` 的真实瓶颈仍在 `DiagnosisLogic::getAssistants()`,允许一并做局部 SQL 优化
* 优先处理:
* `ONLY_FULL_GROUP_BY` 风险
* 原生 SQL / NULL 比较兼容性
* Builder 可替换的 `whereRaw`
*`order` 表相关的潜在保留字问题
* 明确慢点 SQL 的结构优化,避免全表扫描/不必要 join/重复聚合
@@ -0,0 +1,26 @@
{
"id": "conversion-overview-mysql8",
"name": "conversion-overview-mysql8",
"title": "conversion overview mysql8 compatibility",
"description": "",
"status": "completed",
"dev_type": null,
"scope": null,
"package": null,
"priority": "P2",
"creator": "codex-agent",
"assignee": "codex-agent",
"createdAt": "2026-05-07",
"completedAt": "2026-05-11",
"branch": null,
"base_branch": "long-0507",
"worktree_path": null,
"commit": null,
"pr_url": null,
"subtasks": [],
"children": [],
"parent": null,
"relatedFiles": [],
"notes": "",
"meta": {}
}