Reduce logs during statistics import

main
Kevin Belisle 2021-07-08 23:17:57 -04:00
parent 33e6b23a6b
commit 443bde126f
1 changed files with 16 additions and 11 deletions

View File

@ -38,26 +38,31 @@ object StatisticsImporter {
val statsFile = StatsFile.fromJson(file.readText()) val statsFile = StatsFile.fromJson(file.readText())
val playerId = file.nameWithoutExtension val playerId = file.nameWithoutExtension
transaction(database) {
addLogger(StdOutSqlLogger)
val playerStats = emptyMap<String, MutableMap<String, Long>>().toMutableMap() val playerStats = emptyMap<String, MutableMap<String, Long>>().toMutableMap()
transaction(database) {
LiveStatistics.slice(LiveStatistics.type, LiveStatistics.name, LiveStatistics.value) LiveStatistics.slice(LiveStatistics.type, LiveStatistics.name, LiveStatistics.value)
.select { LiveStatistics.playerId eq playerId } .select { LiveStatistics.playerId eq playerId }
.forEach { .forEach {
if (playerStats.containsKey(it[LiveStatistics.type])) { if (playerStats.containsKey(it[LiveStatistics.type])) {
playerStats[it[LiveStatistics.type]]?.put( playerStats[it[LiveStatistics.type]]?.put(
it[LiveStatistics.name], it[LiveStatistics.value]) it[LiveStatistics.name],
it[LiveStatistics.value]
)
} else { } else {
playerStats.put( playerStats.put(
it[LiveStatistics.type], it[LiveStatistics.type],
mapOf<String, Long>( mapOf<String, Long>(
it[LiveStatistics.name] to it[LiveStatistics.name] to
it[LiveStatistics.value]) it[LiveStatistics.value]
.toMutableMap()) )
.toMutableMap()
)
} }
} }
}
transaction(database) {
addLogger(StdOutSqlLogger)
statsFile?.stats?.forEach { type, stats -> statsFile?.stats?.forEach { type, stats ->
stats.forEach { name, value -> stats.forEach { name, value ->
@ -113,7 +118,8 @@ object StatisticsImporter {
UPDATE SET T."Value" = S."Value", T."Rank" = S."Rank" UPDATE SET T."Value" = S."Value", T."Rank" = S."Rank"
WHEN NOT MATCHED THEN WHEN NOT MATCHED THEN
INSERT VALUES (S."PlayerId", S."Type", S."Name", S."Value", S."Rank") INSERT VALUES (S."PlayerId", S."Type", S."Name", S."Value", S."Rank")
""".trimIndent()) """.trimIndent()
)
} }
} }
@ -176,9 +182,8 @@ object StatisticsImporter {
suspend fun getName(id: String): String? { suspend fun getName(id: String): String? {
val response: HttpResponse = val response: HttpResponse =
httpClient.request( httpClient.request(
"https://sessionserver.mojang.com/session/minecraft/profile/${id.replace("-", "")}") { "https://sessionserver.mojang.com/session/minecraft/profile/${id.replace("-", "")}"
method = HttpMethod.Get ) { method = HttpMethod.Get }
}
if (response.status.isSuccess()) { if (response.status.isSuccess()) {
try { try {
return MojangProfileResponse.fromJson(response.readText())?.name return MojangProfileResponse.fromJson(response.readText())?.name