From 10eff256cb80b8f03a413eb9f295445b516b29ff Mon Sep 17 00:00:00 2001 From: BurnyLlama Date: Sat, 9 Oct 2021 23:52:41 +0200 Subject: [PATCH] Minor "refactor". --- libs/database/sqlite2mongo.js | 6 ++-- libs/database/sqlite2mongo/postTasks.js | 39 ++++++++++++++----------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/libs/database/sqlite2mongo.js b/libs/database/sqlite2mongo.js index 8ed9da9..01d6208 100644 --- a/libs/database/sqlite2mongo.js +++ b/libs/database/sqlite2mongo.js @@ -12,9 +12,9 @@ const log = initLog("sqlite2mongo") async function sqlite2mongo() { log("Checking for additions to 'ddnet.sqlite'...") - // await checkForMaps() - // await checkForPlayers() - // await checkForFinishes() + await checkForMaps() + await checkForPlayers() + await checkForFinishes() await postTasks() } diff --git a/libs/database/sqlite2mongo/postTasks.js b/libs/database/sqlite2mongo/postTasks.js index b482a83..45ba008 100644 --- a/libs/database/sqlite2mongo/postTasks.js +++ b/libs/database/sqlite2mongo/postTasks.js @@ -15,7 +15,7 @@ export default async function postTasks() { log("Loading cached info from DDNet...") const cache = decodeMsgpack() - log("Adding total amounts of finishes to maps!") + 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] @@ -25,62 +25,67 @@ export default async function postTasks() { mapFromDB.totalFinishes = map[2] mapFromDB.save() - log(`Processed ${category} map ${i}/${cache.maps[category].length} -> «${map[0]}» with ${map[2]} finishes!`) + log(`Processed ${category} map ${i + 1}/${cache.maps[category].length} -> «${map[0]}» with ${map[2]} finishes!`) } } - log("Adding points to players") - for (const entry of cache.pointsRanks) { + log("Processing points for players...") + for (const i in cache.pointsRanks) { + const entry = cache.pointsRanks[i] const playerFromDB = await Player.findOne({ name: entry[0] }) if (!playerFromDB) continue playerFromDB.points = entry[1] playerFromDB.save() - log(`Processed ${entry[1]} points for ${entry[0]}`) + log(`Processed player ${i + 1}/${cache.pointsRanks.length} -> «${entry[0]}» has ${entry[1]} points!`) } - log("Adding rank points to players") - for (const entry of cache.rankPoints) { + log("Processing rank points for players...") + for (const i in cache.rankPoints) { + const entry = cache.rankPoints[i] const playerFromDB = await Player.findOne({ name: entry[0] }) if (!playerFromDB) continue playerFromDB.rankPoints = entry[1] playerFromDB.save() - log(`Processed ${entry[1]} rank points for ${entry[0]}`) + log(`Processed player ${i + 1}/${cache.pointsRanks.length} -> «${entry[0]}» has ${entry[1]} rank points!`) } - log("Adding team points to players") - for (const entry of cache.teamRankPoints) { + log("Processing team points for players...") + for (const i in cache.teamRankPoints) { + const entry = cache.teamRankPoints[i] const playerFromDB = await Player.findOne({ name: entry[0] }) if (!playerFromDB) continue playerFromDB.teamPoints = entry[1] playerFromDB.save() - log(`Processed ${entry[1]} team points for ${entry[0]}`) + log(`Processed player ${i + 1}/${cache.pointsRanks.length} -> «${entry[0]}» has ${entry[1]} team points!`) } - log("Adding weekly points to players") - for (const entry of cache.pointsThisWeek) { + log("Processing players' points for the last week...") + for (const i of cache.pointsThisWeek) { + const entry = cache.pointsThisWeek[i] const playerFromDB = await Player.findOne({ name: entry[0] }) if (!playerFromDB) continue playerFromDB.pointsThisWeek = entry[1] playerFromDB.save() - log(`Processed ${entry[1]} weekly points for ${entry[0]}`) + log(`Processed player ${i + 1}/${cache.pointsRanks.length} -> «${entry[0]}» got ${entry[1]} points this week!`) } - log("Adding monthly points to players") - for (const entry of cache.teamRankPoints) { + log("Processing players' points for the last month...") + for (const i of cache.pointsThisMonth) { + const entry = cache.pointsThisMonth[i] const playerFromDB = await Player.findOne({ name: entry[0] }) if (!playerFromDB) continue playerFromDB.pointsThisMonth = entry[1] playerFromDB.save() - log(`Processed ${entry[1]} monthly points for ${entry[0]}`) + log(`Processed player ${i + 1}/${cache.pointsRanks.length} -> «${entry[0]}» got ${entry[1]} points this month!`) } } \ No newline at end of file