core: user level update

This commit is contained in:
undefined committed 2021-04-19 13:41:59 +08:00
1 parent 988140c244
commit e06279e26c
3 files changed
+13 -26

No files matched your search

+1 -1
View File
@@ -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",
+2 -13
View File
@@ -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[] = [
{
+10 -12
View File
@@ -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<Udoc> = {
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();
}