1
0
Fork 0

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 playerId = file.nameWithoutExtension
transaction(database) {
addLogger(StdOutSqlLogger)
val playerStats = emptyMap<String, MutableMap<String, Long>>().toMutableMap()
transaction(database) {
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<String, Long>(
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