constnewMapsAmount=(awaitsqlite.get(`SELECT count(Map) FROM maps ${date?`WHERE Timestamp > datetime('${date}')`:''} ORDER BY Timestamp`))['count(Map)']
log(`Found ${newMapsAmount} new maps!`)
letaddedMaps=0
awaitsqlite.each(
`SELECT Map, Server, Points, Stars, Mapper, Timestamp FROM maps ${date?`WHERE Timestamp > datetime('${date}')`:''} ORDER BY Timestamp`,
constnewPlayerAmount=(awaitsqlite.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)']
if(newPlayerAmount===0)returnlog("No new players found...")
log(`Found ${newPlayerAmount} new players!`)
log("Importing new players...")
awaitsqlite.exec("DROP TABLE IF EXISTS temp")
awaitsqlite.exec("CREATE TABLE temp(Name varchar(128) NOT NULL, Timestamp timestamp NOT NULL)")
awaitsqlite.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'!")
letaddedPlayers=0
letoffset=-1
while(offset<newPlayerAmount){
awaitsqlite.each(
`SELECT Name, Timestamp FROM temp LIMIT 10000 OFFSET ${offset+1}`,
constnewFinishAmount=(awaitsqlite.get(`SELECT count(Name) FROM race ${date?`WHERE Timestamp > datetime('${date}')`:''}`))['count(Name)']
if(newFinishAmount===0)returnlog("No new finishes found...")
log(`Found ${newFinishAmount} 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}')` : ''}`)