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:
co-authored by
Claude Opus 4.6
parent
3a4048a29e
commit
df3a9daa65
+11
-1
@@ -1,6 +1,7 @@
|
||||
const express = require('express');
|
||||
const cors = require('cors');
|
||||
const path = require('path');
|
||||
const compression = require('compression');
|
||||
|
||||
const db = require('./db');
|
||||
const { router: authRouter, auth } = require('./routes/auth');
|
||||
@@ -12,9 +13,18 @@ const app = express();
|
||||
|
||||
app.use(cors());
|
||||
app.use(express.json());
|
||||
app.use(express.static(path.join(__dirname, '..', 'public')));
|
||||
app.use(compression());
|
||||
app.use(express.static(path.join(__dirname, '..', 'public'), {
|
||||
maxAge: '1h',
|
||||
etag: true
|
||||
}));
|
||||
|
||||
// 联系人自动补全
|
||||
app.use('/api', (req, res, next) => {
|
||||
res.setHeader('Cache-Control', 'no-cache');
|
||||
next();
|
||||
});
|
||||
|
||||
app.get('/api/contacts', auth, (req, res) => {
|
||||
const field = req.query.field;
|
||||
const allowed = ['boss', 'partner', 'source', 'destination'];
|
||||
|
||||
Reference in New Issue
Block a user