From c3dfa5c6bffb458655b0e278655d7499b1ac9a78 Mon Sep 17 00:00:00 2001 From: BurnyLlama Date: Sat, 2 Oct 2021 18:27:43 +0200 Subject: [PATCH] Fixed bug while importing players. --- libs/database/sqlite2mongo.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/database/sqlite2mongo.js b/libs/database/sqlite2mongo.js index 54c3005..d4bc5c9 100644 --- a/libs/database/sqlite2mongo.js +++ b/libs/database/sqlite2mongo.js @@ -45,14 +45,14 @@ async function checkForPlayers() { const latestPlayer = await Player.findOne({}).sort({ "firstFinish": "desc" }) const date = latestPlayer ? latestPlayer.firstFinish.toISOString().replace(/[TZ]/g, " ").replace(/\.[0-9\s]+/, "") : undefined - const newPlayerAmount = (await sqlite.get(`SELECT count(Name) FROM (SELECT Name, Timestamp FROM (SELECT * FROM race ORDER BY Timestamp ASC, Name ASC) GROUP BY Name) ${date ? `WHERE Timestamp > datetime('${date}')` : ''}`))['count(Name)'] + const newPlayerAmount = (await sqlite.get(`select count(Name) FROM (SELECT Name, Timestamp FROM (SELECT Name, Timestamp FROM (SELECT * FROM race ORDER BY Timestamp ASC, Name ASC) GROUP BY Name) ${date ? `WHERE Timestamp > datetime('${date}')` : ''} ORDER BY Timestamp ASC)`))['count(Name)'] if (newPlayerAmount === 0) return log("No new players found...") log(`Found ${newPlayerAmount} new players!`) log("Importing new players...") await sqlite.exec("DROP TABLE IF EXISTS temp") await sqlite.exec("CREATE TABLE temp(Name varchar(128) NOT NULL, Timestamp timestamp NOT NULL)") - await sqlite.exec(`INSERT INTO TEMP (Name, Timestamp) SELECT Name, Timestamp FROM (SELECT Name, Timestamp FROM (SELECT * FROM race ORDER BY Timestamp ASC, Name ASC) GROUP BY Name) ${date ? `WHERE Timestamp > datetime('${date}')` : ''}`) + await sqlite.exec(`INSERT INTO TEMP (Name, Timestamp) SELECT Name, Timestamp FROM (SELECT Name, Timestamp FROM (SELECT Name, Timestamp FROM (SELECT * FROM race ORDER BY Timestamp ASC, Name ASC) GROUP BY Name) ${date ? `WHERE Timestamp > datetime('${date}')` : ''} ORDER BY Timestamp ASC)`) log("Imported new players into 'temp'!") let addedPlayers = 0