丛林猎手优化
This commit is contained in:
xcy 2024-01-01 09:04:08 +08:00
parent 0e93358e74
commit 381aeb1792
4 changed files with 65 additions and 51 deletions

View File

@ -139,6 +139,10 @@ export abstract class Rank {
//将db里的数据写入到 rank:xxx:sort里
//写入的单条数据为: {uid:score}
// 首先清理redis中sort数据 在从数据库中初始化
await G.ioredis.del(this.getRedisKeySort);
this.db.find({ type: this.type }, {
projection: {
"idKey": 1,
@ -253,13 +257,7 @@ export abstract class Rank {
if (uids && uids.length > 0) {
let res = await this.db.find({ idKey: { $in: uids }, type: this.getType() }).toArray()
switch (this.getType()) {
case "slzd1":
case "slzd2":
case "slzd3":
case "slzd4":
case "slzd5":
case "slzd6":
if (this.type.indexOf("slzd") != -1) {
let ghid = [];
res = res.map(item => {
if (!item.data?.player?.ghid || item.data.utime + 60 < G.time) {
@ -280,8 +278,9 @@ export abstract class Rank {
this.db.updateOne({ idKey: item._id.toHexString(), type: this.getType() }, { $set: { "data.player": res[index].data.player } });
})
}
break;
default: // 排行数据更新逻辑 默认更新playerInfo
} else if (this.type.indexOf('clslCross') != -1) {
// 丛林猎手 跨服排行榜 不需要更新
} else {
let updateUids = [];
res = res.map(item => {
// 没有player 或者 player 过期
@ -290,6 +289,7 @@ export abstract class Rank {
}
return item;
});
let newUserArr = await G.mongodb.collection('user').find(
{ uid: { $in: updateUids } }, { projection: { _id: 0 } }
).toArray();
@ -306,7 +306,8 @@ export abstract class Rank {
})
}
return res.map(ele => ele.data).sort(this.compareSort) as any;
// 按照redis uids 排序顺序排序
return res.sort((a, b) => uids.indexOf(a.idKey) - uids.indexOf(b.idKey)).map(ele => ele.data);
}
return []
}

View File

@ -27,6 +27,11 @@ export class RankClslCross extends Rank {
return Number(val)
}
async getRankData(uid: string) {
let data: rankInfo;
return (await this.db.findOne({ "idKey": uid, "type": this.getType() })).data
}
async addNew(info: rankInfo) {
// 积分大于配置的最小参数,更新数据
if (info.valArr[0] >= this.minStar) {

View File

@ -406,7 +406,15 @@ const crossIndexs: Partial<{ [k in keyof MongodbCollections]: IndexDescription[]
],
clslCrossUser: [
{
key: {uid: 1}, unique: true
key: { uid: 1 },
},
{
key: { ttltime: 1 }, expireAfterSeconds: 7 * 24 * 3600
}
],
clslCrossGroup: [
{
key: { week: 1 },
}
],
rankList: [

View File

@ -13,7 +13,7 @@ export type ResOpen = {
};
export type rankType = 'jjc' | 'tanxian' | 'zhanli' | 'qjzzd' | 'hbzbLocal' | 'hbzbCross' | 'hbzbZbsCross'
| 'slzd1' | 'slzd2' | 'slzd3' | 'slzd4' | 'slzd5' | 'slzd6' | 'clslCross'
| 'slzd1' | 'slzd2' | 'slzd3' | 'slzd4' | 'slzd5' | 'slzd6' | "clslCross"
| 'kbzz' | 'xszm' | 'zccg' | 'gbzl' | 'tujian' | 'wzryCross';
export type rankTypeObj = {