mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-10-25 07:17:23 +08:00
created daily leaderboard clear function
This commit is contained in:
parent
9a3e1749b8
commit
ab13cd439d
2 changed files with 22 additions and 5 deletions
|
|
@ -24,10 +24,8 @@
|
|||
|
||||
### leaderboard
|
||||
|
||||
- Add boardcleartime
|
||||
- How will boards be cleared?
|
||||
- Can there be a function that runs outside of requests
|
||||
- Wait until desired time with setTimeout and then set next timeout
|
||||
- Does clearDailyLeaderboards cause a memory leak?
|
||||
- Try commenting it out and seeing if it makes a difference
|
||||
- Identify bugs
|
||||
- Username not highlighted and added to the bottom if current user made the leaderboard
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,24 @@ const mtRootDir = __dirname.substring(0, __dirname.length - 8); //will this work
|
|||
app.use(express.static(mtRootDir + "/dist"));
|
||||
app.use(bodyParser.json());
|
||||
|
||||
// Initialize database leaderboards if no leaderboards exist
|
||||
// Daily leaderboard clear function
|
||||
function clearDailyLeaderboards() {
|
||||
var nextClear = new Date();
|
||||
nextClear.setHours(24, 0, 0, 0); //next occurrence of 12am
|
||||
let currentTime = new Date();
|
||||
setTimeout(() => {
|
||||
Leaderboard.find({ type: "daily" }, (err, lbs) => {
|
||||
lbs.forEach((lb) => {
|
||||
lb.board = [];
|
||||
lb.resetTime = nextClear;
|
||||
lb.save();
|
||||
});
|
||||
});
|
||||
clearDailyLeaderboards();
|
||||
}, nextClear.getTime() - currentTime.getTime());
|
||||
}
|
||||
|
||||
// Initialize database leaderboards if no leaderboards exist and start clearDailyLeaderboards
|
||||
Leaderboard.findOne((err, lb) => {
|
||||
if (lb === null) {
|
||||
let lb = {
|
||||
|
|
@ -43,6 +60,8 @@ Leaderboard.findOne((err, lb) => {
|
|||
lb.mode2 = 15;
|
||||
Leaderboard.create(lb);
|
||||
}
|
||||
}).then(() => {
|
||||
clearDailyLeaderboards();
|
||||
});
|
||||
|
||||
function authenticateToken(req, res, next) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue