perf(db): 高频查询补索引 + 大列表加合理上限(避免全表下发)

- 启动建表后幂等补索引:orders/finance_records/users/reports/companions/payment_intents/payment_refunds 等高频查询列

- 管理端订单/财务流水/用户列表 LIMIT 500,友圈/评价列表 LIMIT 200,防止无界查询

- expert_services 懒建表后补 expert_id 索引

- 新增回归护栏 list-pagination-index.spec.ts(84 套件/625 用例全绿)
这个提交包含在:
xcbyy
2026-10-19 09:28:02 +08:00
父节点 d665cd6976
当前提交 cbf77a7252
共有 3 个文件被更改,包括 99 次插入 和 3 次删除

查看文件

@@ -1325,6 +1325,7 @@ export class MysqlRepository {
created_at as createdAt
FROM orders
ORDER BY created_at DESC
LIMIT 500
`);
return rows;
}
@@ -1367,6 +1368,7 @@ export class MysqlRepository {
OR claimed_by = ?
OR companion_name IN (SELECT name FROM companions WHERE user_id = ? OR id = ?)
ORDER BY created_at DESC
LIMIT 500
`, [uid, uid, uid, uid, uid]);
return rows;
}
@@ -3102,6 +3104,7 @@ export class MysqlRepository {
created_at as createdAt
FROM finance_records
ORDER BY created_at DESC
LIMIT 500
`);
return rows;
}
@@ -3508,7 +3511,7 @@ export class MysqlRepository {
sql += ' AND status = ?';
params.push(filter.status);
}
sql += ' ORDER BY id ASC';
sql += ' ORDER BY id ASC LIMIT 500';
const [rows]: any = await pool.query(sql, params);
return rows;
}
@@ -4286,7 +4289,7 @@ export class MysqlRepository {
if (where.length > 0) {
sql += ' WHERE ' + where.join(' AND ');
}
sql += ' ORDER BY is_top DESC, created_at DESC';
sql += ' ORDER BY is_top DESC, created_at DESC LIMIT 200';
const [rows]: any = await pool.query(sql, params);
return rows.map((r: any) => {
@@ -4597,7 +4600,7 @@ export class MysqlRepository {
if (where.length > 0) {
sql += ' WHERE ' + where.join(' AND ');
}
sql += ' ORDER BY created_at DESC';
sql += ' ORDER BY created_at DESC LIMIT 200';
const [rows]: any = await pool.query(sql, params);
return rows.map((r: any) => {
@@ -4911,6 +4914,11 @@ export class MysqlRepository {
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
)
`);
try {
await pool.query('ALTER TABLE expert_services ADD INDEX idx_srv_expert (expert_id)');
} catch (_) {
// 索引已存在:忽略
}
const [rows]: any = await pool.query('SELECT * FROM expert_services WHERE expert_id = ? ORDER BY created_at ASC', [expertId]);
if (rows && rows.length > 0) {
return rows.map((r: any) => ({