perf: 系统性能优化 - 数据库索引、缓存、GZIP压缩和查询合并

- 添加3个复合索引提升查询性能 (user_date, user_category, destination)
- 添加GZIP压缩和静态资源缓存 (maxAge: 1h)
- 添加API响应no-cache头
- 添加stats端点2分钟内存缓存 (per-user key, LRU淘汰)
- 合并多次数据库查询为单次查询
- 添加滚动防抖改善移动端体验
- 修复res.once内存泄漏问题

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
lizhilun
2026-03-25 10:25:37 +08:00
co-authored by Claude Opus 4.6
parent 3a4048a29e
commit df3a9daa65
6 changed files with 250 additions and 122 deletions
+14 -3
View File
@@ -1,3 +1,12 @@
// 防抖工具函数
function debounce(fn, delay) {
let timeoutId;
return function(...args) {
clearTimeout(timeoutId);
timeoutId = setTimeout(() => fn.apply(this, args), delay);
};
}
// 全局状态变量(供 app.js 引用)
var orderPage = 1, orderHasMore = true, orderLoading = false;
var otherIncomePage = 1, otherIncomeHasMore = true, otherIncomeLoading = false;
@@ -97,8 +106,8 @@ function renderMilkTeaItem(r) {
'<div class="order-item-bottom"><span>' + (r.source || '') + '</span><span>' + time + '</span></div></div>';
}
// 滚动加载
window.addEventListener('scroll', () => {
// 滚动加载(带防抖)
const handleListScroll = debounce(() => {
const pageListMap = [
{ page: 'orderListPage', list: 'orderList' },
{ page: 'dispatchListPage', list: 'dispatchList' },
@@ -118,7 +127,9 @@ window.addEventListener('scroll', () => {
break;
}
}
});
}, 100);
window.addEventListener('scroll', handleListScroll);
// 兼容旧接口
async function loadOrders(append) { return loadList('orderList', append); }