Skip to content

Commit da26ff3

Browse files
committed
core: fix nLiked (#1128)
1 parent f509ed0 commit da26ff3

5 files changed

Lines changed: 39 additions & 15 deletions

File tree

framework/framework/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"fs-extra": "^11.3.3",
1616
"koa": "^3.1.1",
1717
"koa-body": "^7.0.1",
18-
"koa-compress": "^5.2.0",
18+
"koa-compress": "5.1.1",
1919
"path-to-regexp": "^8.3.0",
2020
"sanitize-filename": "^1.6.3",
2121
"schemastery": "^3.17.2",

packages/hydrooj/src/loader.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,8 @@ export class Loader extends Service {
127127
fork ? 'update' : 'apply', displayPath, configScope,
128128
);
129129
if (fork) {
130-
console.log('update fork', fork, config);
131130
fork.update(config, true);
132131
} else {
133-
console.log('apply plugin', plugin, config);
134132
fork = this.ctx.plugin(plugin, config);
135133
if (!fork) return;
136134
const inner = Object.getPrototypeOf(fork) !== Fiber.prototype
@@ -142,7 +140,6 @@ export class Loader extends Service {
142140
if (!fork.uid || !this.state[key]) return;
143141
const resolved = await this.resolveConfig(plugin, configScope, false);
144142
if (isEqual(this.state[key].config, resolved)) return;
145-
console.log('trigger reload', key, configScope);
146143
this.reloadPlugin(key, configScope);
147144
});
148145
}

packages/hydrooj/src/model/setting.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ DomainUserSetting(Schema.object({
287287

288288
rpInfo: Schema.any().extra('family', 'setting_storage').disabled().hidden(),
289289

290-
...Object.fromEntries(['nAccept', 'nSubmit', 'nLike', 'rp', 'rpdelta', 'rank', 'level', 'join'].map((i) => ([
290+
...Object.fromEntries(['nAccept', 'nSubmit', 'nLiked', 'rp', 'rpdelta', 'rank', 'level', 'join'].map((i) => ([
291291
i, Schema.number().default(0).extra('family', 'setting_storage').disabled().hidden(),
292292
]))),
293293

packages/hydrooj/src/script/problemStat.ts

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,27 @@ import db from '../service/db';
77
const sumStatus = (status) => ({ $sum: { $cond: [{ $eq: ['$status', status] }, 1, 0] } });
88

99
export async function udoc(report) {
10+
const userStats = new Map<string, { nLiked?: number, nAccept?: number, nSubmit?: number }>();
11+
12+
report({ message: 'Udoc nLiked' });
13+
const likedPipeline = [
14+
{
15+
$match: {
16+
docType: document.TYPE_PROBLEM_SOLUTION,
17+
vote: { $gt: 0 },
18+
},
19+
},
20+
{
21+
$group: {
22+
_id: { domainId: '$domainId', uid: '$owner' },
23+
nLiked: { $sum: '$vote' },
24+
},
25+
},
26+
];
27+
for await (const adoc of document.coll.aggregate<any>(likedPipeline, { allowDiskUse: true })) {
28+
userStats.set(`${adoc._id.domainId}/${adoc._id.uid}`, { nLiked: adoc.nLiked });
29+
}
30+
1031
report({ message: 'Udoc' });
1132
const pipeline = [
1233
{
@@ -31,20 +52,26 @@ export async function udoc(report) {
3152
},
3253
},
3354
];
55+
for await (const adoc of db.collection('record').aggregate<any>(pipeline, { allowDiskUse: true })) {
56+
const key = `${adoc._id.domainId}/${adoc._id.uid}`;
57+
const stat = userStats.get(key) || {};
58+
stat.nSubmit = adoc.nSubmit;
59+
stat.nAccept = adoc.nAccept;
60+
userStats.set(key, stat);
61+
}
62+
3463
let bulk = db.collection('domain.user').initializeUnorderedBulkOp();
35-
const cursor = db.collection('record').aggregate<any>(pipeline, { allowDiskUse: true });
36-
for await (const adoc of cursor) {
37-
bulk.find({
38-
domainId: adoc._id.domainId,
39-
uid: adoc._id.uid,
40-
}).updateOne({
64+
for (const [key, stat] of userStats) {
65+
const [domainId, uid] = key.split('/');
66+
bulk.find({ domainId, uid: +uid }).updateOne({
4167
$set: {
42-
nSubmit: adoc.nSubmit,
43-
nAccept: adoc.nAccept,
68+
nSubmit: stat.nSubmit || 0,
69+
nAccept: stat.nAccept || 0,
70+
nLiked: stat.nLiked || 0,
4471
},
4572
});
4673
if (bulk.batches.length > 100) {
47-
await bulk.execute();
74+
await bulk.execute(); // eslint-disable-line no-await-in-loop
4875
bulk = db.collection('domain.user').initializeUnorderedBulkOp();
4976
}
5077
}

packages/ui-default/templates/user_detail.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ <h1 class="section__tab-title">{{ _('Accepted Problems') }}</h1>
153153
</div>
154154
<div class="balancer__body">
155155
<div class="numbox">
156-
<div class="numbox__num medium">{{ udoc.nLike or 0 }}</div>
156+
<div class="numbox__num medium">{{ udoc.nLiked or 0 }}</div>
157157
<div class="numbox__text">{{ _('Solutions Liked') }}</div>
158158
</div>
159159
</div>

0 commit comments

Comments
 (0)