perf: 性能优化与代码质量改进
- 添加4个数据库索引提升查询性能 - 启用ESLint并配置React支持 - 修复ESLint错误(未使用的导入和状态) - 简化Toast组件UI样式 - 移除重复文件(server.js.backup) - 清理.gitignore中的.next目录 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
1e478c2eaa
commit
3975bbed73
@@ -66,6 +66,11 @@ db.exec(`
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (user_id) REFERENCES users(id)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_records_user_month ON records(user_id, date);
|
||||
CREATE INDEX IF NOT EXISTS idx_records_user_category ON records(user_id, category);
|
||||
CREATE INDEX IF NOT EXISTS idx_recurring_user ON recurring_bills(user_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_categories_user ON categories(user_id);
|
||||
`);
|
||||
|
||||
const VALID_RECORD_TYPES = ['income', 'expense'];
|
||||
@@ -312,6 +317,9 @@ app.get('/api/records', authenticate, (req, res) => {
|
||||
}
|
||||
|
||||
if (type && type !== 'all') {
|
||||
if (!VALID_RECORD_TYPES.includes(type)) {
|
||||
return res.status(400).json({ error: '类型参数错误' });
|
||||
}
|
||||
query += ' AND type = ?';
|
||||
params.push(type);
|
||||
}
|
||||
@@ -808,7 +816,7 @@ app.get('/_next/static/:path(*)', (req, res) => {
|
||||
|
||||
app.get('*', (req, res) => {
|
||||
// 检查是否是 Next.js 预渲染的页面
|
||||
let pagePath = req.path === '/' ? '/index.html' : req.path + '.html';
|
||||
const pagePath = req.path === '/' ? '/index.html' : req.path + '.html';
|
||||
const nextPagePath = path.join(__dirname, 'frontend/.next/server/pages', pagePath);
|
||||
|
||||
res.sendFile(nextPagePath, (err) => {
|
||||
|
||||
Reference in New Issue
Block a user