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 { sqlite } from '../init.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("Calculating player points...") const playerAmount = await Player.find({}).count() const playerAgg = Player.aggregate([]) let processedPlayers = 0 for await (const player of playerAgg) { const points = (await sqlite.get(`SELECT sum(Points) FROM maps JOIN (SELECT DISTINCT Map FROM race WHERE Name = "${player.name}") AS r ON maps.Map = r.Map`))['sum(Points)'] player.points = points Player.updateOne({ name: player.name }, { rankPoints: points }, () => log(`Task ${processedPlayers}/${playerAmount} >> Player «${player.name}» has ${points} points!`)) ++processedPlayers } log("Done calculating points!") }