diff --git a/src/public/rank/rank.ts b/src/public/rank/rank.ts index 74e7286..674cf04 100644 --- a/src/public/rank/rank.ts +++ b/src/public/rank/rank.ts @@ -139,7 +139,7 @@ export abstract class Rank { //将db里的数据,写入到 rank:xxx:sort里 //写入的单条数据为: {uid:score} - + // 首先清理redis中sort数据 在从数据库中初始化 await G.ioredis.del(this.getRedisKeySort); @@ -257,61 +257,57 @@ 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": - let ghid = []; - res = res.map(item => { - if (!item.data?.player?.ghid || item.data.utime + 60 < G.time) { - ghid.push(G.mongodb.conversionId(item.idKey)); - } - return item; - }) - if (ghid.length > 0) { - let ghinfo = await G.mongodb.collection("gonghui").find( - { _id: { $in: ghid } }, { projection: { name: 1 } } - ).toArray(); - ghinfo.forEach(item => { - let index = res.findIndex(x => x.idKey == item._id.toHexString()); - res[index].data.player = { - ghName: item.name, - ghId: item._id.toHexString(), - }; - this.db.updateOne({ idKey: item._id.toHexString(), type: this.getType() }, { $set: { "data.player": res[index].data.player } }); - }) + if (this.type.indexOf("slzd") != -1) { + let ghid = []; + res = res.map(item => { + if (!item.data?.player?.ghid || item.data.utime + 60 < G.time) { + ghid.push(G.mongodb.conversionId(item.idKey)); } - break; - default: // 排行数据更新逻辑 默认更新playerInfo - let updateUids = []; - res = res.map(item => { - // 没有player 或者 player 过期 - if (!item.data?.player || item.data.utime + 60 < G.time) { - updateUids.push(item.idKey); - } - return item; - }); - let newUserArr = await G.mongodb.collection('user').find( - { uid: { $in: updateUids } }, { projection: { _id: 0 } } + return item; + }) + if (ghid.length > 0) { + let ghinfo = await G.mongodb.collection("gonghui").find( + { _id: { $in: ghid } }, { projection: { name: 1 } } ).toArray(); - - newUserArr.forEach(item => { - // 每次遍历查找? - let index = res.findIndex(x => x.idKey == item.uid); - - res[index].data.player = item; - this.db.updateOne({ idKey: item.uid, type: this.getType() }, { $set: { "data.player": item } }); - - // 跟新redis score - // this.setRankData(item.uid, res[index].data as any); + ghinfo.forEach(item => { + let index = res.findIndex(x => x.idKey == item._id.toHexString()); + res[index].data.player = { + ghName: item.name, + ghId: item._id.toHexString(), + }; + this.db.updateOne({ idKey: item._id.toHexString(), type: this.getType() }, { $set: { "data.player": res[index].data.player } }); }) + } + } else if (this.type.indexOf('clslCross') != -1) { + // 丛林猎手 跨服排行榜 不需要更新 + } else { + let updateUids = []; + res = res.map(item => { + // 没有player 或者 player 过期 + if (!item.data?.player || item.data.utime + 60 < G.time) { + updateUids.push(item.idKey); + } + return item; + }); + + let newUserArr = await G.mongodb.collection('user').find( + { uid: { $in: updateUids } }, { projection: { _id: 0 } } + ).toArray(); + + newUserArr.forEach(item => { + // 每次遍历查找? + let index = res.findIndex(x => x.idKey == item.uid); + + res[index].data.player = item; + this.db.updateOne({ idKey: item.uid, type: this.getType() }, { $set: { "data.player": item } }); + + // 跟新redis score + // this.setRankData(item.uid, res[index].data as any); + }) } // 按照redis uids 排序顺序排序 - return res.sort((a,b)=>uids.indexOf(a.idKey)-uids.indexOf(b.idKey)).map(ele => ele.data); + return res.sort((a, b) => uids.indexOf(a.idKey) - uids.indexOf(b.idKey)).map(ele => ele.data); } return [] } diff --git a/src/public/rank/rank_clsl.ts b/src/public/rank/rank_clsl.ts index 3849146..714a3b9 100644 --- a/src/public/rank/rank_clsl.ts +++ b/src/public/rank/rank_clsl.ts @@ -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) { diff --git a/src/setMongodb.ts b/src/setMongodb.ts index f7a267b..5573466 100644 --- a/src/setMongodb.ts +++ b/src/setMongodb.ts @@ -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: [ diff --git a/src/shared/protocols/rank/PtlOpen.ts b/src/shared/protocols/rank/PtlOpen.ts index fcc7e84..f878176 100644 --- a/src/shared/protocols/rank/PtlOpen.ts +++ b/src/shared/protocols/rank/PtlOpen.ts @@ -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 = {