From 443bde126f7b8552fa8253f5103d5e0e1f9d2efb Mon Sep 17 00:00:00 2001 From: Kevin Belisle Date: Thu, 8 Jul 2021 23:17:57 -0400 Subject: [PATCH] Reduce logs during statistics import --- .../xyz/etztech/stonks/StatisticsImporter.kt | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/app/src/main/kotlin/xyz/etztech/stonks/StatisticsImporter.kt b/app/src/main/kotlin/xyz/etztech/stonks/StatisticsImporter.kt index 8adb484..12cd533 100644 --- a/app/src/main/kotlin/xyz/etztech/stonks/StatisticsImporter.kt +++ b/app/src/main/kotlin/xyz/etztech/stonks/StatisticsImporter.kt @@ -38,26 +38,31 @@ object StatisticsImporter { val statsFile = StatsFile.fromJson(file.readText()) val playerId = file.nameWithoutExtension + val playerStats = emptyMap>().toMutableMap() + transaction(database) { - addLogger(StdOutSqlLogger) - - val playerStats = emptyMap>().toMutableMap() - LiveStatistics.slice(LiveStatistics.type, LiveStatistics.name, LiveStatistics.value) .select { LiveStatistics.playerId eq playerId } .forEach { if (playerStats.containsKey(it[LiveStatistics.type])) { playerStats[it[LiveStatistics.type]]?.put( - it[LiveStatistics.name], it[LiveStatistics.value]) + it[LiveStatistics.name], + it[LiveStatistics.value] + ) } else { playerStats.put( it[LiveStatistics.type], mapOf( it[LiveStatistics.name] to - it[LiveStatistics.value]) - .toMutableMap()) + it[LiveStatistics.value] + ) + .toMutableMap() + ) } } + } + transaction(database) { + addLogger(StdOutSqlLogger) statsFile?.stats?.forEach { type, stats -> stats.forEach { name, value -> @@ -113,7 +118,8 @@ object StatisticsImporter { UPDATE SET T."Value" = S."Value", T."Rank" = S."Rank" WHEN NOT MATCHED THEN 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? { val response: HttpResponse = httpClient.request( - "https://sessionserver.mojang.com/session/minecraft/profile/${id.replace("-", "")}") { - method = HttpMethod.Get - } + "https://sessionserver.mojang.com/session/minecraft/profile/${id.replace("-", "")}" + ) { method = HttpMethod.Get } if (response.status.isSuccess()) { try { return MojangProfileResponse.fromJson(response.readText())?.name