perf: V0.9.1-0.9.3 性能优化(count/featured 全表→聚合、请求内缓存、二级索引、PSI 未读铃铛)

- V0.9.1 (P0): Model::count() 改 SELECT COUNT(*);新增请求内 identity-map 缓存;
  Product::featured() 改 WHERE+ LIMIT 避免全表
- V0.9.2 (P1): schema.sql 内联二级索引 + install/upgrades/009_perf_indexes.sql 幂等迁移
- V0.9.3 (P1): psi_unread_events() 改 COUNT + JSON_CONTAINS,消除每页 all()+循环
This commit is contained in:
2026-08-08 19:47:35 +08:00
parent a2dac3b095
commit 4d36a284ff
5 changed files with 193 additions and 25 deletions
+3 -1
View File
@@ -14,7 +14,9 @@ class Product extends Model
}
public function featured(int $limit = 6): array
{
return array_slice(array_filter($this->all(), fn($p) => ($p['status'] ?? 1) == 1), 0, $limit);
// V0.9.1:改用 whereLimit('status',1,$limit)MySQL 下走带 LIMIT 的索引查询,
// 不再 SELECT * 全表拉回再 array_filter(原写法每次请求都全表扫描)。
return $this->whereLimit('status', 1, $limit);
}
public function specsArray($p): array
{