ddstats-server/libs/database/sqlite2mongo/postTasks.js

31 lines
1.0 KiB
JavaScript
Raw Normal View History

2021-10-06 19:52:40 +02:00
import Finish from '../../../schemas/Finish.js'
import Level from '../../../schemas/Level.js'
import Player from '../../../schemas/Player.js'
import initLog from '../../utills/log.js'
import decodeMsgpack from './decodeMsgpack.js'
2021-10-06 19:52:40 +02:00
const log = initLog("sqlite2mongo")
2021-10-06 20:36:20 +02:00
/**
* This handles some post-tasks that run after the initial checks.
* @module libs/database/sqlite2mongo/postTasks
*/
2021-10-06 19:52:40 +02:00
export default async function postTasks() {
log("Post tasks...")
log("Loading cached info from DDNet...")
const cache = decodeMsgpack()
2021-10-06 19:52:40 +02:00
log("Adding total amounts of finishes to maps!")
for (const category in cache.maps) {
for (const i in cache.maps[category]) {
const map = cache.maps[category][i]
const mapFromDB = await Level.findOne({ name: map[0] })
if (!mapFromDB) continue
2021-10-06 19:52:40 +02:00
mapFromDB.totalFinishes = map[2]
mapFromDB.save()
log(`Processed ${category} map ${i}/${cache.maps[category].length} -> «${map[0]}» with ${map[2]} finishes!`)
}
}
2021-10-06 19:52:40 +02:00
}