diff --git a/CHANGELOG.md b/CHANGELOG.md index adc76bd528f..e22adc6e720 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 0.20.34 + +* `Repos`: + * `Common`: + * Improve default `set` realization of `KeyValuesRepo` + ## 0.20.33 * `Colors` diff --git a/gradle.properties b/gradle.properties index 4c6f9a4ca18..c57242f2d36 100644 --- a/gradle.properties +++ b/gradle.properties @@ -15,5 +15,5 @@ crypto_js_version=4.1.1 # Project data group=dev.inmo -version=0.20.33 -android_code_version=239 +version=0.20.34 +android_code_version=240 diff --git a/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/full/FullKeyValuesCacheRepo.kt b/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/full/FullKeyValuesCacheRepo.kt index e139256d539..2aae6cfc227 100644 --- a/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/full/FullKeyValuesCacheRepo.kt +++ b/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/full/FullKeyValuesCacheRepo.kt @@ -192,6 +192,10 @@ open class FullKeyValuesCacheRepo( } } + override suspend fun set(toSet: Map>) { + super.set(toSet) + } + override suspend fun removeWithValue(v: Value) { super.removeWithValue(v) } diff --git a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/KeyValuesRepo.kt b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/KeyValuesRepo.kt index 57e8a6331c9..670d23ff5b5 100644 --- a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/KeyValuesRepo.kt +++ b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/KeyValuesRepo.kt @@ -1,5 +1,6 @@ package dev.inmo.micro_utils.repos +import dev.inmo.micro_utils.common.diff import dev.inmo.micro_utils.pagination.* import dev.inmo.micro_utils.pagination.utils.doForAllWithNextPaging import dev.inmo.micro_utils.pagination.utils.getAllWithNextPaging @@ -130,6 +131,14 @@ interface KeyValuesRepo : ReadKeyValuesRepo, WriteKeyVal remove(toRemove) } + + override suspend fun set(toSet: Map>) { + toSet.forEach { (k, v) -> + val diff = getAll(k).diff(v) + remove(k, diff.removed.map { it.value }) + add(k, diff.added.map { it.value }) + } + } } typealias OneToManyKeyValueRepo = KeyValuesRepo