M8 P2 | getSummary/getTrend 优化:使用 findByDateRange 替代 findAll 全表扫描 #159
Loading…
x
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
问题
ReadingController.getSummary()和getTrend()使用LearningActivityRepository.findAll(userId)拉取用户全部 DailyLearningActivity 记录,不做日期过滤。getSummary:计算 totalSeconds/weekSeconds/todaySeconds,只需近 7 天 + 全量聚合getTrend:只需要最近 N 天(N ≤ 90)用户数据量大时性能差。
建议
getTrend改用findByDateRange(userId, from, to)只查询需要的天数getSummary的总量(totalSeconds/activeDays)可缓存或用 aggregate 查询代码位置
reading.controller.ts:97—getSummary调用findAllreading.controller.ts:143—getTrend调用findAll审计来源
Batch D 审查 F1。
修复
getTrend改用findByDateRange(userId, from, now),只查需要的天数。getSummary用 90 天范围查询 week/today +findAll获取 total。