diff --git a/packages/hydrooj/package.json b/packages/hydrooj/package.json index 56792e584..75099f9d0 100644 --- a/packages/hydrooj/package.json +++ b/packages/hydrooj/package.json @@ -1,6 +1,6 @@ { "name": "hydrooj", - "version": "2.23.5", + "version": "2.23.6", "bin": "bin/hydrooj.js", "main": "dist/loader.js", "typings": "dist/loader.d.ts", diff --git a/packages/hydrooj/src/model/builtin.ts b/packages/hydrooj/src/model/builtin.ts index 0eb48def0..baad95f9c 100644 --- a/packages/hydrooj/src/model/builtin.ts +++ b/packages/hydrooj/src/model/builtin.ts @@ -255,19 +255,8 @@ PRIV.PRIV_DEFAULT = PRIV.PRIV_USER_PROFILE + PRIV.PRIV_CREATE_FILE + PRIV.PRIV_DELETE_FILE_SELF; -// [10, 1] means that people whose rank is less than 1% will get Level 10 -export const LEVELS = [ - [10, 1], - [9, 2], - [8, 10], - [7, 20], - [6, 30], - [5, 40], - [4, 70], - [3, 90], - [2, 95], - [1, 100], -]; +// people whose rank is less than 1% will get Level 10 +export const LEVELS = [100, 90, 70, 55, 40, 30, 20, 10, 5, 2, 1]; export const BUILTIN_USERS: Udoc[] = [ { diff --git a/packages/hydrooj/src/script/rating.ts b/packages/hydrooj/src/script/rating.ts index 27f6125c6..fbb33bc99 100644 --- a/packages/hydrooj/src/script/rating.ts +++ b/packages/hydrooj/src/script/rating.ts @@ -84,36 +84,34 @@ async function runContest(...arg: any[]) { } export async function calcLevel(domainId: string, report: Function) { - const dudocs = await domain.getMultiUserInDomain(domainId).sort('rp', -1).toArray(); - if (!dudocs.length) return; + const ducnt = await domain.getMultiUserInDomain(domainId).count(); + if (!ducnt) return; let last = { rp: null }; let rank = 0; let count = 0; const coll = global.Hydro.service.db.collection('domain.user'); + const ducur = domain.getMultiUserInDomain(domainId).project({ rp: 1 }).sort({ rp: -1 }); let bulk = coll.initializeUnorderedBulkOp(); - for (const dudoc of dudocs) { + while (await ducur.hasNext()) { + const dudoc = await ducur.next(); count++; if (!dudoc.rp) dudoc.rp = null; if (dudoc.rp !== last.rp) rank = count; bulk.find({ _id: dudoc._id }).updateOne({ $set: { rank } }); last = dudoc; - if (count % 1000 === 0) report({ message: `#${count}: Rank ${rank}` }); + if (count % 100 === 0) report({ message: `#${count}: Rank ${rank}` }); } await bulk.execute(); - if (!rank) { - report({ message: 'No one has rp' }); - return; - } const levels = global.Hydro.model.builtin.LEVELS; bulk = coll.initializeUnorderedBulkOp(); for (let i = 0; i < levels.length; i++) { - report({ message: 'Updating users levelled {0}'.format(levels[i][0]) }); + report({ message: 'Updating users levelled {0}'.format(i) }); const query: FilterQuery = { domainId, - $and: [{ rank: { $lte: (levels[i][1] * rank) / 100 } }], + $and: [{ rank: { $lte: (levels[i] * count) / 100 } }], }; - if (i < levels.length - 1) query.$and.push({ rank: { $gt: (levels[i + 1][1] * rank) / 100 } }); - bulk.find(query).update({ $set: { level: levels[i][0] } }); + if (i < levels.length) query.$and.push({ rank: { $gt: (levels[i + 1] * count) / 100 } }); + bulk.find(query).update({ $set: { level: i } }); } await bulk.execute(); }