From 1277cb6e5c7c411b35c82edf1801ca6089f8fea9 Mon Sep 17 00:00:00 2001 From: TheSaminator Date: Sun, 17 Apr 2022 12:27:08 -0400 Subject: [PATCH] Optimize --- src/jvmMain/kotlin/starshipfights/auth/providers.kt | 5 +---- src/jvmMain/kotlin/starshipfights/info/views_gdpr.kt | 4 ++-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/jvmMain/kotlin/starshipfights/auth/providers.kt b/src/jvmMain/kotlin/starshipfights/auth/providers.kt index bf19be4..6ba8a5b 100644 --- a/src/jvmMain/kotlin/starshipfights/auth/providers.kt +++ b/src/jvmMain/kotlin/starshipfights/auth/providers.kt @@ -258,10 +258,7 @@ interface AuthProvider { val ownedShips = ShipInDrydock.filter(ShipInDrydock::owningAdmiral eq admiralId).toList() val shipType = call.parameters["ship"]?.let { param -> ShipType.values().singleOrNull { it.toUrlSlug() == param } }!! - val shipPrice = shipType.buyPrice(admiral, ownedShips) - - if (shipPrice == null) - throw NotFoundException() + val shipPrice = shipType.buyPrice(admiral, ownedShips) ?: throw NotFoundException() if (shipPrice > admiral.money) redirect("/admiral/${admiralId}/manage" + withErrorMessage("You cannot afford that ship")) diff --git a/src/jvmMain/kotlin/starshipfights/info/views_gdpr.kt b/src/jvmMain/kotlin/starshipfights/info/views_gdpr.kt index 2467f22..6663362 100644 --- a/src/jvmMain/kotlin/starshipfights/info/views_gdpr.kt +++ b/src/jvmMain/kotlin/starshipfights/info/views_gdpr.kt @@ -55,7 +55,7 @@ suspend fun ApplicationCall.privateInfo(): String { } val getAdmirals = userBattles.associate { record -> val admiralId = if (record.hostUser == userId) record.hostAdmiral else record.guestAdmiral - record.id to async { Admiral.get(admiralId) } + record.id to userAdmirals.singleOrNull { it.id == admiralId } } val getOpponents = userBattles.associate { record -> val (opponentId, opponentAdmiralId) = if (record.hostUser == userId) record.guestUser to record.guestAdmiral else record.hostUser to record.hostAdmiral @@ -65,7 +65,7 @@ suspend fun ApplicationCall.privateInfo(): String { Triple( getShips.mapValues { (_, deferred) -> deferred.await() }, - getAdmirals.mapValues { (_, deferred) -> deferred.await() }, + getAdmirals, getOpponents.mapValues { (_, deferred) -> deferred.let { (u, a) -> u.await() to a.await() } } ) } -- 2.25.1