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

31 lines
1.0 KiB
JavaScript

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'
const log = initLog("sqlite2mongo")
/**
* This handles some post-tasks that run after the initial checks.
* @module libs/database/sqlite2mongo/postTasks
*/
export default async function postTasks() {
log("Post tasks...")
log("Loading cached info from DDNet...")
const cache = decodeMsgpack()
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
mapFromDB.totalFinishes = map[2]
mapFromDB.save()
log(`Processed ${category} map ${i}/${cache.maps[category].length} -> «${map[0]}» with ${map[2]} finishes!`)
}
}
}