Skip to content

Commit b9194cd

Browse files
committed
fix hydro total balloon
1 parent 71db74d commit b9194cd

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

packages/server/service/fetcher.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class BasicFetcher extends Service implements IBasicFetcher {
4444
}
4545

4646
[Service.init]() {
47-
this.ctx.interval(() => this.cron().catch(this.logger.error), 10000);
47+
this.ctx.interval(() => this.cron().catch(this.logger.error), 15000);
4848
}
4949

5050
async cron() {
@@ -205,8 +205,10 @@ class HydroFetcher extends BasicFetcher {
205205
if (all) this.logger.info('Sync all balloons...');
206206
const { body } = await fetch(`/d/${this.contest.domainId}/contest/${this.contest.id}/balloon?todo=${all ? 'false' : 'true'}`);
207207
if (!body?.bdocs?.length) return;
208-
for (const balloon of body.bdocs) {
209-
const teamTotal = await this.ctx.db.balloon.find({ teamid: balloon.uid, time: { $lt: (balloon.time * 1000).toFixed(0) } });
208+
const baloons = body.bdocs.map((b) => ({ ...b, time: mongoId(b._id).timestamp * 1000 })).sort((a, b) => a.time - b.time);
209+
for (const balloon of baloons) {
210+
balloon.time = mongoId(balloon._id).timestamp * 1000;
211+
const teamTotal = await this.ctx.db.balloon.find({ teamid: balloon.uid, time: { $lt: balloon.time } });
210212
const encourage = teamTotal.length < (config.freezeEncourage ?? 0);
211213
const totalDict = {};
212214
for (const t of teamTotal) {
@@ -215,16 +217,17 @@ class HydroFetcher extends BasicFetcher {
215217
const shouldPrint = this.contest.info.freeze_time ? (balloon.time * 1000) < this.contest.info.freeze_time || encourage : true;
216218
if (!shouldPrint && !balloon.sent) await this.setBalloonDone(balloon.balloonid);
217219
const contestproblem = {
218-
id: String.fromCharCode(this.contest.info.pids.indexOf(balloon.pid) + 65),
220+
id: balloon.pid.toString(),
221+
short_name: String.fromCharCode(this.contest.info.pids.indexOf(balloon.pid) + 65),
219222
name: body.pdict[balloon.pid].title,
220223
rgb: this.contest.info.balloon[balloon.pid].color,
221224
color: this.contest.info.balloon[balloon.pid].name,
222225
};
223-
await this.ctx.db.balloon.update({ balloonid: balloon._id }, {
226+
await this.ctx.db.balloon.update({ balloonid: balloon._id.substring(0, 8) }, {
224227
$set: {
225-
balloonid: balloon._id,
226-
time: mongoId(balloon._id).timestamp,
227-
problem: contestproblem.id,
228+
balloonid: balloon._id.substring(0, 8),
229+
time: balloon.time,
230+
problem: contestproblem.short_name,
228231
contestproblem,
229232
team: body.udict[balloon.uid].displayName,
230233
teamid: balloon.uid,

0 commit comments

Comments
 (0)