From 5d450e06326ffe7d386a6ce42fb719e31c3fb178 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 8 Feb 2022 23:08:13 +0600 Subject: [PATCH 1/2] start 0.9.7 --- CHANGELOG.md | 2 ++ gradle.properties | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e34e39cab8..da96201ee72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Changelog +## 0.9.7 + ## 0.9.6 * `Repos`: diff --git a/gradle.properties b/gradle.properties index bf512cd5da5..12b4beb8694 100644 --- a/gradle.properties +++ b/gradle.properties @@ -45,5 +45,5 @@ dokka_version=1.6.10 # Project data group=dev.inmo -version=0.9.6 -android_code_version=96 +version=0.9.7 +android_code_version=97 From ccc1dd7857e4c5b0c64205869995739659e91980 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 8 Feb 2022 23:21:14 +0600 Subject: [PATCH 2/2] fixes in ExposedOneToManyKeyValueRepo and includeWebsocketHandling --- CHANGELOG.md | 7 +++++++ .../inmo/micro_utils/ktor/server/FlowsWebsocket.kt | 14 ++++++-------- .../onetomany/ExposedOneToManyKeyValueRepo.kt | 9 +++++++-- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index da96201ee72..2fda808c1e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ ## 0.9.7 +* `Repos`: + * `Exposed`: + * Fix in `ExposedOneToManyKeyValueRepo` - now it will not use `insertIgnore` +* `Ktor`: + * `Server`: + * `Route#includeWebsocketHandling` now will check that `WebSockets` feature and install it if not + ## 0.9.6 * `Repos`: diff --git a/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/FlowsWebsocket.kt b/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/FlowsWebsocket.kt index bd7d9a32670..d26cd03cb08 100644 --- a/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/FlowsWebsocket.kt +++ b/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/FlowsWebsocket.kt @@ -2,25 +2,23 @@ package dev.inmo.micro_utils.ktor.server import dev.inmo.micro_utils.coroutines.safely import dev.inmo.micro_utils.ktor.common.* +import io.ktor.application.featureOrNull +import io.ktor.application.install import io.ktor.http.cio.websocket.* import io.ktor.routing.Route +import io.ktor.routing.application import io.ktor.websocket.webSocket import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.collect import kotlinx.serialization.SerializationStrategy -private suspend fun DefaultWebSocketSession.checkReceivedAndCloseIfExists() { - if (incoming.tryReceive() != null) { - close() - throw CorrectCloseException - } -} - fun Route.includeWebsocketHandling( suburl: String, flow: Flow, converter: (T) -> StandardKtorSerialInputData ) { + application.apply { + featureOrNull(io.ktor.websocket.WebSockets) ?: install(io.ktor.websocket.WebSockets) + } webSocket(suburl) { safely { flow.collect { diff --git a/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/onetomany/ExposedOneToManyKeyValueRepo.kt b/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/onetomany/ExposedOneToManyKeyValueRepo.kt index 20a0e57af1c..0c839ea7834 100644 --- a/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/onetomany/ExposedOneToManyKeyValueRepo.kt +++ b/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/onetomany/ExposedOneToManyKeyValueRepo.kt @@ -35,10 +35,15 @@ open class ExposedOneToManyKeyValueRepo( if (select { keyColumn.eq(k).and(valueColumn.eq(v)) }.limit(1).count() > 0) { return@mapNotNull null } - insertIgnore { + val insertResult = insert { it[keyColumn] = k it[valueColumn] = v - }.getOrNull(keyColumn) ?.let { k to v } + } + if (insertResult.insertedCount > 0) { + k to v + } else { + null + } } ?: emptyList() } }.forEach { _onNewValue.emit(it) }