Skip to content

Commit d42f73e

Browse files
author
robot
committed
why so 慢
1 parent 35206cc commit d42f73e

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

routes/dailyProblem.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,21 @@ const { success, fail } = require("../utils/request");
77
const { getDay } = require("../utils/day");
88
const { startTime } = require("../config/index");
99

10+
const A = [];
11+
for (const [login, solution] of Object.entries(mySolutions)) {
12+
A.push({ count: solution.filter(Boolean).length, ...users[login] });
13+
}
14+
15+
const rankings = A.sort((a, b) => b.count - a.count);
16+
17+
for (let i = 0; i < rankings.length; i++) {
18+
if (i > 0 && rankings[i].count === rankings[i - 1].count) {
19+
rankings[i].rank = rankings[i - 1].rank;
20+
} else {
21+
rankings[i].rank = i + 1;
22+
}
23+
}
24+
1025
router.get("/api/v1/daily-problem", async (ctx) => {
1126
if (ctx.query.date && ctx.query.date > new Date().getTime()) {
1227
// 活动没有开始,给大家一个体验版本(两道题)
@@ -50,21 +65,6 @@ router.get("/api/v1/daily-problem/solution", async (ctx) => {
5065
}
5166
});
5267

53-
const A = [];
54-
for (const [login, solution] of Object.entries(mySolutions)) {
55-
A.push({ count: solution.filter(Boolean).length, ...users[login] });
56-
}
57-
58-
const rankings = A.sort((a, b) => b.count - a.count);
59-
60-
for (let i = 0; i < rankings.length; i++) {
61-
if (i > 0 && rankings[i].count === rankings[i - 1].count) {
62-
rankings[i].rank = rankings[i - 1].rank;
63-
} else {
64-
rankings[i].rank = i + 1;
65-
}
66-
}
67-
6868
router.get("/api/v1/daily-problem/ranking", async (ctx) => {
6969
ctx.body = success(rankings);
7070
});

0 commit comments

Comments
 (0)