Skip to content

Commit be9a2f3

Browse files
committed
cache total result
1 parent 9337d0f commit be9a2f3

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

src/server/node-functions/[[server]].js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ async function getLeaderBoardFromTime(periodMs = 24 * 3600 * 1000, limit = 30) {
5353
const sorted = Object.entries(counts)
5454
.sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]))
5555
.slice(0, limit);
56-
return sorted;
56+
return sorted.map((array) => { return { bvid: array[0], count: array[1] } });
5757
}
5858

5959
async function getCachedLeaderBoard(range) {
@@ -316,7 +316,6 @@ app.get(['/api/leaderboard', '/leaderboard'], async (req, res) => {
316316
if (!board || board.length === 0) {
317317
return res.json({ success: false, list: [] });
318318
}
319-
let list = board.map((array) => { return { bvid: array[0], count: array[1] } });
320319
// no type or type != 2: add backward capability
321320
// if (!proc_type || proc_type !== 2) {
322321
// await Promise.all(list.map(async (item, index) => {
@@ -341,7 +340,7 @@ app.get(['/api/leaderboard', '/leaderboard'], async (req, res) => {
341340
// }
342341
// }));
343342
// }
344-
res.json({ success: true, list: list });
343+
res.json({ success: true, list: board });
345344
} catch (error) {
346345
res.status(500).json({ success: false, error: error.message });
347346
}

src/server/server.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ async function getLeaderBoardFromTime(periodMs = 24 * 3600 * 1000, limit = 30) {
5353
const sorted = Object.entries(counts)
5454
.sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]))
5555
.slice(0, limit);
56-
return sorted;
56+
return sorted.map((array) => { return { bvid: array[0], count: array[1] } });
5757
}
5858

5959
async function getCachedLeaderBoard(range) {
@@ -316,7 +316,6 @@ app.get(['/api/leaderboard', '/leaderboard'], async (req, res) => {
316316
if (!board || board.length === 0) {
317317
return res.json({ success: false, list: [] });
318318
}
319-
let list = board.map((array) => { return { bvid: array[0], count: array[1] } });
320319
// no type or type != 2: add backward capability
321320
// if (!proc_type || proc_type !== 2) {
322321
// await Promise.all(list.map(async (item, index) => {
@@ -341,7 +340,7 @@ app.get(['/api/leaderboard', '/leaderboard'], async (req, res) => {
341340
// }
342341
// }));
343342
// }
344-
res.json({ success: true, list: list });
343+
res.json({ success: true, list: board });
345344
} catch (error) {
346345
res.status(500).json({ success: false, error: error.message });
347346
}

0 commit comments

Comments
 (0)