- 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()+循环
36 lines
1016 B
PHP
36 lines
1016 B
PHP
<?php
|
||
namespace App\Models;
|
||
|
||
use Core\Model;
|
||
|
||
class Product extends Model
|
||
{
|
||
protected $table = 'products';
|
||
protected $orderBy = 'sort_order';
|
||
|
||
public function byCategory(int $catId): array
|
||
{
|
||
return $this->whereAll('category_id', $catId);
|
||
}
|
||
public function featured(int $limit = 6): array
|
||
{
|
||
// V0.9.1:改用 whereLimit('status',1,$limit),MySQL 下走带 LIMIT 的索引查询,
|
||
// 不再 SELECT * 全表拉回再 array_filter(原写法每次请求都全表扫描)。
|
||
return $this->whereLimit('status', 1, $limit);
|
||
}
|
||
public function specsArray($p): array
|
||
{
|
||
$s = $p['specs'] ?? '';
|
||
if (is_array($s)) return $s;
|
||
$dec = json_decode((string)$s, true);
|
||
return is_array($dec) ? $dec : [];
|
||
}
|
||
public function galleryArray($p): array
|
||
{
|
||
$g = $p['gallery'] ?? '';
|
||
if (is_array($g)) return $g;
|
||
$dec = json_decode((string)$g, true);
|
||
return is_array($dec) ? $g : [];
|
||
}
|
||
}
|