perf: V0.9.4 商品列表分页 + sitemap 文件缓存 + banner/asset/gzip/类型修复

- P1: Product::listing() 分页(WHERE status=1+LIMIT/OFFSET+总数),ProductController 改用并加翻页器,消除列表全表
- P1: outputSitemap() 加 storage/cache/sitemap.xml 文件缓存(TTL 3600s),消除每次爬虫全表
- P2: 首页 banner 改 whereLimit('status',1,20)
- P2: asset() 追加 ?v=filemtime 版本串,theme.css 改后自动击穿 1y 浏览器缓存
- P2: nginx 启用 gzip(文本资源压缩)
- P2: Model::count() $val 隐式可空改 mixed(PHP 8.4+ 弃用)
This commit is contained in:
2026-08-08 23:53:52 +08:00
parent 2285998618
commit d5c1edefae
8 changed files with 83 additions and 7 deletions
+9 -3
View File
@@ -10,11 +10,15 @@ class ProductController extends Controller
{
$product = new Product();
$category = new Category();
$perPage = 12;
$page = max(1, (int)($_GET['page'] ?? 1));
$catId = isset($_GET['cat']) ? (int)$_GET['cat'] : 0;
$products = $catId
? $product->byCategory($catId)
: array_filter($product->all(), fn($p) => ($p['status'] ?? 1) == 1);
// V0.9.4:列表改为分页查询(WHERE status=1 + LIMIT/OFFSET + 总数),不再全表拉回。
$res = $product->listing($page, $perPage, $catId ?: null);
$products = $res['items'];
$total = $res['total'];
$totalPages = max(1, (int) ceil($total / $perPage));
$cat = $catId ? $category->find($catId) : null;
$catName = $cat['name'] ?? '';
@@ -56,6 +60,8 @@ class ProductController extends Controller
'categories'=> $category->all(),
'activeCat' => $catId,
'cat' => $cat,
'page' => $page,
'totalPages'=> $totalPages,
]);
}