✨ feat(db): role索引修改,去掉无索引的sort

This commit is contained in:
liangtongchuan
2023-05-07 16:14:10 +08:00
parent e2ffab7345
commit ee0fdf116c
+5 -3
View File
@@ -105,13 +105,15 @@ export class Teraph {
/** /**
* 角色字段接口 * 角色字段接口
*/ */
@index({ roleId: 1, serverId: 1 }) @index({ roleId: 1 })
@index({ roleName: 1 }) @index({ roleName: 1 })
@index({ towerLv: -1, towerUpTime: 1 }) @index({ towerLv: -1, towerUpTime: 1 })
@index({ topLineupCe: 1, updatedAt: 1 }) @index({ topLineupCe: 1, updatedAt: 1 })
@index({ ce: -1 }) @index({ ce: -1 })
@index({ 'userInfo.uid': 1, serverId: 1 }) @index({ 'userInfo.uid': 1, serverId: 1 })
@index({ loginTime: 1 }) @index({ loginTime: 1 })
@index({ serverId: 1, loginTime: 1 })
@index({ lv: 1, loginTime: 1 })
@index({ createdAt: 1 }) @index({ createdAt: 1 })
export default class Role extends BaseModel { export default class Role extends BaseModel {
@@ -667,7 +669,7 @@ export default class Role extends BaseModel {
public static async getRecommedList(minLv: number, maxLv: number, time: number) { public static async getRecommedList(minLv: number, maxLv: number, time: number) {
const result: RoleType[] = await RoleROModel.find({ loginTime: { $gt: time }, lv: { $gte: minLv, $lte: maxLv }, hasInit: true }, { _id: 0 }) const result: RoleType[] = await RoleROModel.find({ loginTime: { $gt: time }, lv: { $gte: minLv, $lte: maxLv }, hasInit: true }, { _id: 0 })
.select(ROLE_SELECT.SHOW_FRIEND_APPLY_LIST) .select(ROLE_SELECT.SHOW_FRIEND_APPLY_LIST)
.sort({ quitTime: -1, lv: -1, ce: -1 }) .sort({ lv: -1, ce: -1 })
.limit(200).lean({ getters: true, virtuals: true }); .limit(200).lean({ getters: true, virtuals: true });
return result; return result;
} }
@@ -681,7 +683,7 @@ export default class Role extends BaseModel {
] ]
}, { _id: 0 }) }, { _id: 0 })
.select(ROLE_SELECT.SHOW_FRIEND_APPLY_LIST) .select(ROLE_SELECT.SHOW_FRIEND_APPLY_LIST)
.sort({ quitTime: -1, lv: -1, ce: -1 }) .sort({ lv: -1, ce: -1 })
.limit(200).lean({ getters: true, virtuals: true }); .limit(200).lean({ getters: true, virtuals: true });
return result; return result;
} }