Improve Performance

Signed-off-by: Chaoscaot <max@maxsp.de>
This commit is contained in:
2025-12-02 21:34:35 +01:00
parent 0a7a753c48
commit a089d42d9a
8 changed files with 45 additions and 60 deletions
@@ -23,11 +23,17 @@ import de.steamwar.plugins.SWPermissionCheck
import de.steamwar.plugins.getUser
import de.steamwar.sql.SteamwarUser
import de.steamwar.sql.UserPerm
import io.ktor.http.*
import io.ktor.server.application.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
import kotlinx.serialization.Serializable
import io.ktor.http.HttpStatusCode
import io.ktor.server.application.ApplicationCall
import io.ktor.server.application.call
import io.ktor.server.application.install
import io.ktor.server.response.respond
import io.ktor.server.routing.Route
import io.ktor.server.routing.delete
import io.ktor.server.routing.get
import io.ktor.server.routing.put
import io.ktor.server.routing.route
import kotlinx.serialization.Serializable;
@Serializable
data class RespondPrefix(val name: String, val colorCode: String, val chatPrefix: String)
@@ -76,7 +82,12 @@ fun Route.configureUserPerms() {
val prefixs = UserPerm.prefixes[prefix]!!
call.respond(RespondUserPermsPrefix(RespondPrefix(prefix.name, prefixs.colorCode, prefixs.chatPrefix), perms))
call.respond(
RespondUserPermsPrefix(
RespondPrefix(prefix.name, prefixs.colorCode, prefixs.chatPrefix),
perms
)
)
}
put("/prefix/{prefix}") {
val (user, prefix) = call.receivePermission("prefix", isPrefix = true) ?: return@put
@@ -112,7 +123,10 @@ fun Route.configureUserPerms() {
}
}
suspend fun ApplicationCall.receivePermission(fieldName: String = "perm", isPrefix: Boolean = false): Pair<SteamwarUser, UserPerm>? {
suspend fun ApplicationCall.receivePermission(
fieldName: String = "perm",
isPrefix: Boolean = false
): Pair<SteamwarUser, UserPerm>? {
val user = request.getUser()
if (user == null) {
respond(HttpStatusCode.BadRequest)