sqlite2mongo now supports finishes!

This commit is contained in:
BurnyLlama 2021-10-02 17:19:57 +02:00
parent c97f75a982
commit 218b755e6d

View File

@ -80,41 +80,39 @@ async function checkForPlayers() {
async function checkForFinishes() { async function checkForFinishes() {
log("Checking for new players...") log("Checking for new finishes...")
const latestFinish = await Finish.findOne({}).sort({ "firstFinish": "desc" }) const latestFinish = await Finish.findOne({}).sort({ "date": "desc" })
const date = latestFinish ? latestFinish.firstFinish.toISOString().replace(/[TZ]/g, " ").replace(/\.[0-9\s]+/, "") : undefined const date = latestFinish ? latestFinish.date.toISOString().replace(/[TZ]/g, " ").replace(/\.[0-9\s]+/, "") : undefined
const newFinishAmount = (await sqlite.get(`SELECT count(Name) FROM race ${date ? `WHERE Timestamp > datetime('${date}')` : ''}`))['count(Name)'] const newFinishAmount = (await sqlite.get(`SELECT count(Name) FROM race ${date ? `WHERE Timestamp > datetime('${date}')` : ''}`))['count(Name)']
if (newFinishAmount === 0) return log("No new finishes found...") if (newFinishAmount === 0) return log("No new finishes found...")
log(`Found ${newFinishAmount} new players!`) log(`Found ${newFinishAmount} new finishes!`)
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}')` : ''}`)
// log("Imported new players into 'temp'!")
// let addedPlayers = 0 let addedFinishes = 0
// let offset = -1 let offset = -1
// while (offset < newFinishAmount) { while (offset < newFinishAmount) {
// await sqlite.each( await sqlite.each(
// `SELECT Name, Timestamp FROM temp LIMIT 10000 OFFSET ${offset + 1}`, `SELECT * FROM race ${date ? `WHERE Timestamp > datetime('${date}')` : ''} ORDER BY Timestamp LIMIT 5000 OFFSET ${offset + 1}`,
// [], [],
// async (err, player) => { async (err, finish) => {
// if (err) return log(err) if (err) return log(err)
// if (addedPlayers >= newFinishAmount) return {} if (addedFinishes >= newFinishAmount) return {}
// Player.create({ Finish.create({
// name: player.Name, map: finish.Map,
// firstFinish: player.Timestamp === '0000-00-00 00:00:00' ? new Date('January 1, 1970 00:00:00 UTC') : new Date(`${player.Timestamp}+00:00`) time: finish.Time,
// }).then(() => { date: finish.Timestamp === '0000-00-00 00:00:00' ? new Date('January 1, 1970 00:00:00 UTC') : new Date(`${finish.Timestamp}+00:00`),
// ++addedPlayers serverLocation: finish.Server ?? '',
// log(`Added player ${addedPlayers}/${newFinishAmount} -> ${player.Name}`) player: finish.Name
// }) }).then(() => {
// } ++addedFinishes
// ) log(`Added finish ${addedFinishes}/${newFinishAmount} -> At ${finish.Timestamp} «${finish.Name}» completed «${finish.Map}» in ${finish.Time} s`)
// offset += 10000 })
// } }
)
offset += 5000
}
} }
@ -124,6 +122,7 @@ async function sqlite2mongo() {
await checkForMaps() await checkForMaps()
await checkForPlayers() await checkForPlayers()
await checkForFinishes()
} }
export default sqlite2mongo export default sqlite2mongo