From 8e62dd460ca2f5944d1ba8e12becd371e5a77cbd Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 23 Mar 2021 13:46:35 +0600 Subject: [PATCH 1/7] start 0.4.31 --- CHANGELOG.md | 2 ++ gradle.properties | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 60dfc95d187..857b59af9c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Changelog +## 0.4.31 + ## 0.4.30 * `Versions`: diff --git a/gradle.properties b/gradle.properties index 7cf9f57a1bd..84584516678 100644 --- a/gradle.properties +++ b/gradle.properties @@ -44,5 +44,5 @@ dokka_version=1.4.20 # Project data group=dev.inmo -version=0.4.30 -android_code_version=34 +version=0.4.31 +android_code_version=35 From 08c371c142e2b91a186163b0594385c088e5423a Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 24 Mar 2021 13:01:15 +0600 Subject: [PATCH 2/7] add repos.cache --- CHANGELOG.md | 2 + repos/cache/build.gradle | 17 +++++ .../repos/cache/KeyValueCacheRepo.kt | 42 +++++++++++ .../repos/cache/KeyValuesCacheRepo.kt | 74 +++++++++++++++++++ repos/cache/src/main/AndroidManifest.xml | 1 + settings.gradle | 1 + 6 files changed, 137 insertions(+) create mode 100644 repos/cache/build.gradle create mode 100644 repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/KeyValueCacheRepo.kt create mode 100644 repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/KeyValuesCacheRepo.kt create mode 100644 repos/cache/src/main/AndroidManifest.xml diff --git a/CHANGELOG.md b/CHANGELOG.md index 857b59af9c8..6afc4c0a46f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## 0.4.31 +* Add subproject `repos.cache` + ## 0.4.30 * `Versions`: diff --git a/repos/cache/build.gradle b/repos/cache/build.gradle new file mode 100644 index 00000000000..a847ec69fcb --- /dev/null +++ b/repos/cache/build.gradle @@ -0,0 +1,17 @@ +plugins { + id "org.jetbrains.kotlin.multiplatform" + id "org.jetbrains.kotlin.plugin.serialization" + id "com.android.library" +} + +apply from: "$mppProjectWithSerializationPresetPath" + +kotlin { + sourceSets { + commonMain { + dependencies { + api internalProject("micro_utils.repos.common") + } + } + } +} \ No newline at end of file diff --git a/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/KeyValueCacheRepo.kt b/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/KeyValueCacheRepo.kt new file mode 100644 index 00000000000..0648dddb8f6 --- /dev/null +++ b/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/KeyValueCacheRepo.kt @@ -0,0 +1,42 @@ +package dev.inmo.micro_utils.repos.cache + +import dev.inmo.micro_utils.repos.* +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.flow.* +import kotlinx.coroutines.sync.Mutex +import kotlinx.coroutines.sync.withLock + +open class KeyValueCacheRepo( + protected val parentRepo: KeyValueRepo, + protected val cachedValuesCount: Int, + scope: CoroutineScope = CoroutineScope(Dispatchers.Default) +) : KeyValueRepo by parentRepo { + protected open val cache = mutableMapOf() + protected open val cacheStack = ArrayList(cachedValuesCount) + protected val syncMutex = Mutex() + protected val onNewJob = parentRepo.onNewValue.onEach { putCacheValue(it.first, it.second) }.launchIn(scope) + protected val onRemoveJob = parentRepo.onValueRemoved.onEach { removeCacheValue(it) }.launchIn(scope) + + protected suspend fun putCacheValue(k: Key, v: Value) = syncMutex.withLock { + if (cache.size >= cachedValuesCount) { + val key = cacheStack.removeAt(0) + cache.remove(key) + } + cacheStack.add(k) + cache[k] = v + } + + protected suspend fun removeCacheValue(k: Key) = syncMutex.withLock { + val i = cacheStack.indexOf(k) + if (i >= 0) { + val key = cacheStack.removeAt(i) + cache.remove(key) + } + } + + override suspend fun get(k: Key): Value? = syncMutex.withLock { + cache[k] ?: parentRepo.get(k) ?.also { cache[k] = it } + } + override suspend fun contains(key: Key): Boolean = cache.containsKey(key) || parentRepo.contains(key) +} diff --git a/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/KeyValuesCacheRepo.kt b/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/KeyValuesCacheRepo.kt new file mode 100644 index 00000000000..54f46cc1717 --- /dev/null +++ b/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/KeyValuesCacheRepo.kt @@ -0,0 +1,74 @@ +package dev.inmo.micro_utils.repos.cache + +import dev.inmo.micro_utils.pagination.Pagination +import dev.inmo.micro_utils.pagination.PaginationResult +import dev.inmo.micro_utils.pagination.utils.paginate +import dev.inmo.micro_utils.pagination.utils.reverse +import dev.inmo.micro_utils.repos.* +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.flow.* +import kotlinx.coroutines.sync.Mutex +import kotlinx.coroutines.sync.withLock + +open class KeyValuesCacheRepo( + protected val parentRepo: KeyValuesRepo, + protected val cachedValuesCount: Int, + scope: CoroutineScope = CoroutineScope(Dispatchers.Default) +) : KeyValuesRepo by parentRepo { + protected open val cache = mutableMapOf>() + protected open val cacheStack = ArrayList(cachedValuesCount) + protected val syncMutex = Mutex() + protected val onNewJob = parentRepo.onNewValue.onEach { putCacheValue(it.first, it.second) }.launchIn(scope) + protected val onRemoveJob = parentRepo.onValueRemoved.onEach { removeCacheValue(it.first, it.second) }.launchIn(scope) + protected val onDataClearedJob = parentRepo.onDataCleared.onEach { clearCacheValues(it) }.launchIn(scope) + + protected suspend fun putCacheValues(k: Key, v: List) = syncMutex.withLock { + if (cache.size >= cachedValuesCount) { + val key = cacheStack.removeAt(0) + cache.remove(key) + } + cacheStack.add(k) + cache[k] = v + } + protected suspend fun putCacheValue(k: Key, v: Value) = syncMutex.withLock { + cache[k] ?.let { + cache[k] = it + v + } + } ?: putCacheValues(k, listOf(v)) + + protected suspend fun removeCacheValue(k: Key, v: Value) = syncMutex.withLock { + cache[k] ?.let { + val newList = it - v + if (newList.isEmpty()) { + cache.remove(k) + cacheStack.remove(k) + } else { + cache[k] = newList + } + } + } + + protected suspend fun clearCacheValues(k: Key) = syncMutex.withLock { + val i = cacheStack.indexOf(k) + if (i >= 0) { + val key = cacheStack.removeAt(i) + cache.remove(key) + } + } + + override suspend fun get(k: Key, pagination: Pagination, reversed: Boolean): PaginationResult { + return cache[k] ?.paginate( + pagination.let { if (reversed) it.reverse(count(k)) else it } + ) ?.let { + if (reversed) it.copy(results = it.results.reversed()) else it + } ?: parentRepo.get(k, pagination, reversed) + } + override suspend fun getAll(k: Key, reversed: Boolean): List { + return cache[k] ?.let { + if (reversed) it.reversed() else it + } ?: parentRepo.getAll(k, reversed) + } + override suspend fun contains(k: Key, v: Value): Boolean = cache[k] ?.contains(v) ?: parentRepo.contains(k, v) + override suspend fun contains(k: Key): Boolean = cache.containsKey(k) || parentRepo.contains(k) +} diff --git a/repos/cache/src/main/AndroidManifest.xml b/repos/cache/src/main/AndroidManifest.xml new file mode 100644 index 00000000000..6abbe185efb --- /dev/null +++ b/repos/cache/src/main/AndroidManifest.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index ea4cd8a08b3..5d0afc1c814 100644 --- a/settings.gradle +++ b/settings.gradle @@ -11,6 +11,7 @@ String[] includes = [ ":pagination:ktor:server", ":mime_types", ":repos:common", + ":repos:cache", ":repos:exposed", ":repos:inmemory", ":repos:ktor:client", From c4a08e52e599ea13113d0cdd1edada97cc6aedcf Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 24 Mar 2021 13:11:15 +0600 Subject: [PATCH 3/7] update kotlin --- CHANGELOG.md | 2 ++ gradle.properties | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6afc4c0a46f..ec99ece5c80 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## 0.4.31 +* `Versions`: + * `Kotlin`: `1.4.31` -> `1.4.32` * Add subproject `repos.cache` ## 0.4.30 diff --git a/gradle.properties b/gradle.properties index 84584516678..3b8fde88d41 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ kotlin.incremental.js=true android.useAndroidX=true android.enableJetifier=true -kotlin_version=1.4.31 +kotlin_version=1.4.32 kotlin_coroutines_version=1.4.3 kotlin_serialisation_core_version=1.1.0 kotlin_exposed_version=0.29.1 From 2d662f91b3e2bde256ff57cec4ae696ee62380d5 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 29 Mar 2021 17:57:36 +0600 Subject: [PATCH 4/7] updates in coroutines --- CHANGELOG.md | 4 ++++ .../coroutines/FlowSubscription.kt | 24 ++++++++++++++----- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ec99ece5c80..2f9823c93ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ * `Versions`: * `Kotlin`: `1.4.31` -> `1.4.32` * Add subproject `repos.cache` +* `Coroutines`: + * Rewrite `subscribeSafelyWithoutExceptions` + * Now `subscribeSafelyWithoutExceptions` will use default handler instead of skipping + * New extension `subscribeSafelySkippingExceptions` ## 0.4.30 diff --git a/coroutines/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/FlowSubscription.kt b/coroutines/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/FlowSubscription.kt index 26588ac166c..76546375293 100644 --- a/coroutines/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/FlowSubscription.kt +++ b/coroutines/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/FlowSubscription.kt @@ -25,13 +25,25 @@ inline fun Flow.subscribeSafely( } /** - * Use [subscribeSafelyWithoutExceptions], but all exceptions inside of [safely] will be skipped + * Use [subscribeSafelyWithoutExceptions], but all exceptions will be passed to [defaultSafelyExceptionHandler] */ inline fun Flow.subscribeSafelyWithoutExceptions( scope: CoroutineScope, noinline block: suspend (T) -> Unit -) = subscribeSafely( - scope, - {}, - block -) +) = subscribe(scope) { + safelyWithoutExceptions { + block(it) + } +} + +/** + * Use [subscribeSafelyWithoutExceptions], but all exceptions inside of [safely] will be skipped + */ +inline fun Flow.subscribeSafelySkippingExceptions( + scope: CoroutineScope, + noinline block: suspend (T) -> Unit +) = subscribe(scope) { + safelyWithoutExceptions({ /* skip exceptions */ }) { + block(it) + } +} From c1557cff27096318c66818ba8b3707769e75746f Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 29 Mar 2021 19:39:10 +0600 Subject: [PATCH 5/7] huge update with crud caching, common doForAll/getAll and deprecations in old ones doForAll --- CHANGELOG.md | 19 +++++- .../pagination/PaginationResult.kt | 16 +++++ .../micro_utils/pagination/WalkPagination.kt | 4 +- repos/cache/build.gradle | 1 + .../micro_utils/repos/cache/CRUDCacheRepo.kt | 24 +++++++ .../inmo/micro_utils/repos/cache/KVCache.kt | 41 ++++++++++++ .../repos/cache/KeyValueCacheRepo.kt | 32 ++------- .../repos/cache/KeyValuesCacheRepo.kt | 53 +++------------ .../repos/OneToManyKeyValueRepo.kt | 15 ++--- .../micro_utils/repos/StandartKeyValueRepo.kt | 3 +- .../pagination/CRUDPaginationExtensions.kt | 26 +++---- .../pagination/CommonPaginationExtensions.kt | 67 +++++++++++++++++++ .../KeyValuePaginationExtensions.kt | 15 +++-- .../OneToManyPaginationExtensions.kt | 17 +++-- 14 files changed, 223 insertions(+), 110 deletions(-) create mode 100644 repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/CRUDCacheRepo.kt create mode 100644 repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/KVCache.kt create mode 100644 repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/CommonPaginationExtensions.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f9823c93ce..3c3664fe683 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,11 +4,28 @@ * `Versions`: * `Kotlin`: `1.4.31` -> `1.4.32` -* Add subproject `repos.cache` +* `Pagination`: + * New extensions `PaginationResult.changeResultsUnchecked` and `PaginationResult.changeResults` for mapping results + with the same parameters, but different data + * Extension `PaginationResult.thisPageIfNotEmpty` now is typed and will return `PaginationResult?` with the same + generic type as income `PaginationResult` + * New extension `PaginationResult.currentPageIfNotEmpty` - shortcut for `PaginationResult.thisPageIfNotEmpty` * `Coroutines`: * Rewrite `subscribeSafelyWithoutExceptions` * Now `subscribeSafelyWithoutExceptions` will use default handler instead of skipping * New extension `subscribeSafelySkippingExceptions` +* `Repos` + * New subproject `repos.cache` - this subproject will contain repos with data caching mechanisms + * `Pagination` + * New common functions. They were created as replacements for currently available for more comfortable work + with repos pagination: + * `doForAll` + * `doForAllWithNextPaging` + * `doForAllWithCurrentPaging` + * `getAll` + * `getAllWithNextPaging` + * `getAllWithCurrentPaging` + * Most old `doForAll` methods have been deprecated ## 0.4.30 diff --git a/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/PaginationResult.kt b/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/PaginationResult.kt index 35c3f3939a8..fbc092069d4 100644 --- a/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/PaginationResult.kt +++ b/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/PaginationResult.kt @@ -12,6 +12,22 @@ data class PaginationResult( fun emptyPaginationResult() = PaginationResult(0, 0, emptyList(), 0) +/** + * @return New [PaginationResult] with [data] without checking of data sizes equality + */ +fun PaginationResult.changeResultsUnchecked( + data: List +): PaginationResult = PaginationResult(page, pagesNumber, data, size) +/** + * @return New [PaginationResult] with [data] with checking of data sizes equality + */ +fun PaginationResult.changeResults( + data: List +): PaginationResult { + require(data.size == results.size) + return changeResultsUnchecked(data) +} + fun List.createPaginationResult( pagination: Pagination, commonObjectsNumber: Long diff --git a/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/WalkPagination.kt b/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/WalkPagination.kt index aed3d2716fa..05c1087fed8 100644 --- a/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/WalkPagination.kt +++ b/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/WalkPagination.kt @@ -21,8 +21,10 @@ inline fun PaginationResult<*>.nextPageIfNotEmpty() = if (results.isNotEmpty()) } @Suppress("NOTHING_TO_INLINE") -inline fun PaginationResult<*>.thisPageIfNotEmpty(): Pagination? = if (results.isNotEmpty()) { +inline fun PaginationResult.thisPageIfNotEmpty(): PaginationResult? = if (results.isNotEmpty()) { this } else { null } + +inline fun PaginationResult.currentPageIfNotEmpty() = thisPageIfNotEmpty() diff --git a/repos/cache/build.gradle b/repos/cache/build.gradle index a847ec69fcb..e128b1e3cff 100644 --- a/repos/cache/build.gradle +++ b/repos/cache/build.gradle @@ -11,6 +11,7 @@ kotlin { commonMain { dependencies { api internalProject("micro_utils.repos.common") + api internalProject("micro_utils.repos.inmemory") } } } diff --git a/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/CRUDCacheRepo.kt b/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/CRUDCacheRepo.kt new file mode 100644 index 00000000000..22ffbb489c9 --- /dev/null +++ b/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/CRUDCacheRepo.kt @@ -0,0 +1,24 @@ +package dev.inmo.micro_utils.repos.cache + +import dev.inmo.micro_utils.repos.* +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.flow.launchIn +import kotlinx.coroutines.flow.onEach + +open class CRUDCacheRepo( + protected val parentRepo: CRUDRepo, + protected val kvCache: KVCache, + scope: CoroutineScope = CoroutineScope(Dispatchers.Default), + protected val idGetter: (ObjectType) -> IdType +) : CRUDRepo by parentRepo { + protected val onNewJob = parentRepo.newObjectsFlow.onEach { kvCache.set(idGetter(it), it) }.launchIn(scope) + protected val onUpdatedJob = parentRepo.updatedObjectsFlow.onEach { kvCache.set(idGetter(it), it) }.launchIn(scope) + protected val onRemoveJob = parentRepo.deletedObjectsIdsFlow.onEach { kvCache.unset(it) }.launchIn(scope) + + override suspend fun getById(id: IdType): ObjectType? = kvCache.get(id) ?: (parentRepo.getById(id) ?.also { + kvCache.set(id, it) + }) + + override suspend fun contains(id: IdType): Boolean = kvCache.contains(id) || parentRepo.contains(id) +} diff --git a/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/KVCache.kt b/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/KVCache.kt new file mode 100644 index 00000000000..b75a741496d --- /dev/null +++ b/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/KVCache.kt @@ -0,0 +1,41 @@ +package dev.inmo.micro_utils.repos.cache + +import dev.inmo.micro_utils.repos.* +import dev.inmo.micro_utils.repos.pagination.getAllWithNextPaging +import kotlinx.coroutines.sync.Mutex +import kotlinx.coroutines.sync.withLock + +interface KVCache : KeyValueRepo + +open class SimpleKVCache( + protected val cachedValuesCount: Int, + private val kvParent: KeyValueRepo = MapKeyValueRepo() +) : KVCache, KeyValueRepo by kvParent { + protected open val cacheStack = ArrayList(cachedValuesCount) + protected val syncMutex = Mutex() + + protected suspend fun makeUnset(toUnset: List) { + cacheStack.removeAll(toUnset) + kvParent.unset(toUnset) + } + + override suspend fun set(toSet: Map) { + syncMutex.withLock { + if (toSet.size > cachedValuesCount) { + cacheStack.clear() + + kvParent.unset(getAllWithNextPaging { kvParent.keys(it) }) + val keysToInclude = toSet.keys.drop(toSet.size - cachedValuesCount) + + cacheStack.addAll(keysToInclude) + kvParent.set(keysToInclude.associateWith { toSet.getValue(it) }) + } else { + makeUnset(cacheStack.take(toSet.size)) + } + } + } + + override suspend fun unset(toUnset: List) { + syncMutex.withLock { makeUnset(toUnset) } + } +} diff --git a/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/KeyValueCacheRepo.kt b/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/KeyValueCacheRepo.kt index 0648dddb8f6..86d865afe03 100644 --- a/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/KeyValueCacheRepo.kt +++ b/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/KeyValueCacheRepo.kt @@ -9,34 +9,12 @@ import kotlinx.coroutines.sync.withLock open class KeyValueCacheRepo( protected val parentRepo: KeyValueRepo, - protected val cachedValuesCount: Int, + protected val kvCache: KVCache, scope: CoroutineScope = CoroutineScope(Dispatchers.Default) ) : KeyValueRepo by parentRepo { - protected open val cache = mutableMapOf() - protected open val cacheStack = ArrayList(cachedValuesCount) - protected val syncMutex = Mutex() - protected val onNewJob = parentRepo.onNewValue.onEach { putCacheValue(it.first, it.second) }.launchIn(scope) - protected val onRemoveJob = parentRepo.onValueRemoved.onEach { removeCacheValue(it) }.launchIn(scope) + protected val onNewJob = parentRepo.onNewValue.onEach { kvCache.set(it.first, it.second) }.launchIn(scope) + protected val onRemoveJob = parentRepo.onValueRemoved.onEach { kvCache.unset(it) }.launchIn(scope) - protected suspend fun putCacheValue(k: Key, v: Value) = syncMutex.withLock { - if (cache.size >= cachedValuesCount) { - val key = cacheStack.removeAt(0) - cache.remove(key) - } - cacheStack.add(k) - cache[k] = v - } - - protected suspend fun removeCacheValue(k: Key) = syncMutex.withLock { - val i = cacheStack.indexOf(k) - if (i >= 0) { - val key = cacheStack.removeAt(i) - cache.remove(key) - } - } - - override suspend fun get(k: Key): Value? = syncMutex.withLock { - cache[k] ?: parentRepo.get(k) ?.also { cache[k] = it } - } - override suspend fun contains(key: Key): Boolean = cache.containsKey(key) || parentRepo.contains(key) + override suspend fun get(k: Key): Value? = kvCache.get(k) ?: parentRepo.get(k) ?.also { kvCache.set(k, it) } + override suspend fun contains(key: Key): Boolean = kvCache.contains(key) || parentRepo.contains(key) } diff --git a/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/KeyValuesCacheRepo.kt b/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/KeyValuesCacheRepo.kt index 54f46cc1717..26b12af4fd2 100644 --- a/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/KeyValuesCacheRepo.kt +++ b/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/KeyValuesCacheRepo.kt @@ -13,62 +13,25 @@ import kotlinx.coroutines.sync.withLock open class KeyValuesCacheRepo( protected val parentRepo: KeyValuesRepo, - protected val cachedValuesCount: Int, + protected val kvCache: KVCache>, scope: CoroutineScope = CoroutineScope(Dispatchers.Default) ) : KeyValuesRepo by parentRepo { - protected open val cache = mutableMapOf>() - protected open val cacheStack = ArrayList(cachedValuesCount) - protected val syncMutex = Mutex() - protected val onNewJob = parentRepo.onNewValue.onEach { putCacheValue(it.first, it.second) }.launchIn(scope) - protected val onRemoveJob = parentRepo.onValueRemoved.onEach { removeCacheValue(it.first, it.second) }.launchIn(scope) - protected val onDataClearedJob = parentRepo.onDataCleared.onEach { clearCacheValues(it) }.launchIn(scope) - - protected suspend fun putCacheValues(k: Key, v: List) = syncMutex.withLock { - if (cache.size >= cachedValuesCount) { - val key = cacheStack.removeAt(0) - cache.remove(key) - } - cacheStack.add(k) - cache[k] = v - } - protected suspend fun putCacheValue(k: Key, v: Value) = syncMutex.withLock { - cache[k] ?.let { - cache[k] = it + v - } - } ?: putCacheValues(k, listOf(v)) - - protected suspend fun removeCacheValue(k: Key, v: Value) = syncMutex.withLock { - cache[k] ?.let { - val newList = it - v - if (newList.isEmpty()) { - cache.remove(k) - cacheStack.remove(k) - } else { - cache[k] = newList - } - } - } - - protected suspend fun clearCacheValues(k: Key) = syncMutex.withLock { - val i = cacheStack.indexOf(k) - if (i >= 0) { - val key = cacheStack.removeAt(i) - cache.remove(key) - } - } + protected val onNewJob = parentRepo.onNewValue.onEach { kvCache.set(it.first, kvCache.get(it.first) ?.plus(it.second) ?: listOf(it.second)) }.launchIn(scope) + protected val onRemoveJob = parentRepo.onValueRemoved.onEach { kvCache.set(it.first, kvCache.get(it.first) ?.minus(it.second) ?: return@onEach) }.launchIn(scope) + protected val onDataClearedJob = parentRepo.onDataCleared.onEach { kvCache.unset(it) }.launchIn(scope) override suspend fun get(k: Key, pagination: Pagination, reversed: Boolean): PaginationResult { - return cache[k] ?.paginate( + return kvCache.get(k) ?.paginate( pagination.let { if (reversed) it.reverse(count(k)) else it } ) ?.let { if (reversed) it.copy(results = it.results.reversed()) else it } ?: parentRepo.get(k, pagination, reversed) } override suspend fun getAll(k: Key, reversed: Boolean): List { - return cache[k] ?.let { + return kvCache.get(k) ?.let { if (reversed) it.reversed() else it } ?: parentRepo.getAll(k, reversed) } - override suspend fun contains(k: Key, v: Value): Boolean = cache[k] ?.contains(v) ?: parentRepo.contains(k, v) - override suspend fun contains(k: Key): Boolean = cache.containsKey(k) || parentRepo.contains(k) + override suspend fun contains(k: Key, v: Value): Boolean = kvCache.get(k) ?.contains(v) ?: parentRepo.contains(k, v) + override suspend fun contains(k: Key): Boolean = kvCache.contains(k) || parentRepo.contains(k) } diff --git a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/OneToManyKeyValueRepo.kt b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/OneToManyKeyValueRepo.kt index b08e10ff5da..e899c78c2e8 100644 --- a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/OneToManyKeyValueRepo.kt +++ b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/OneToManyKeyValueRepo.kt @@ -1,6 +1,7 @@ package dev.inmo.micro_utils.repos import dev.inmo.micro_utils.pagination.* +import dev.inmo.micro_utils.repos.pagination.getAllWithNextPaging import kotlinx.coroutines.flow.Flow interface ReadOneToManyKeyValueRepo : Repo { @@ -12,14 +13,12 @@ interface ReadOneToManyKeyValueRepo : Repo { suspend fun count(k: Key): Long suspend fun count(): Long - suspend fun getAll(k: Key, reversed: Boolean = false): List = mutableListOf().also { list -> - doWithPagination { - get(k, it).also { - list.addAll(it.results) - }.nextPageIfNotEmpty() - } - if (reversed) { - list.reverse() + suspend fun getAll(k: Key, reversed: Boolean = false): List { + val results = getAllWithNextPaging { get(k, it) } + return if (reversed) { + results.reversed() + } else { + results } } diff --git a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/StandartKeyValueRepo.kt b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/StandartKeyValueRepo.kt index 449396889c9..7747120478a 100644 --- a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/StandartKeyValueRepo.kt +++ b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/StandartKeyValueRepo.kt @@ -1,6 +1,7 @@ package dev.inmo.micro_utils.repos import dev.inmo.micro_utils.pagination.* +import dev.inmo.micro_utils.repos.pagination.doAllWithCurrentPaging import kotlinx.coroutines.flow.Flow interface ReadStandardKeyValueRepo : Repo { @@ -41,7 +42,7 @@ suspend inline fun WriteStandardKeyValueRepo.unsetWithV interface StandardKeyValueRepo : ReadStandardKeyValueRepo, WriteStandardKeyValueRepo { override suspend fun unsetWithValues(toUnset: List) = toUnset.forEach { v -> - doWithPagination { + doAllWithCurrentPaging { keys(v, it).also { unset(it.results) } diff --git a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/CRUDPaginationExtensions.kt b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/CRUDPaginationExtensions.kt index e626262f229..ae2a786b6c3 100644 --- a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/CRUDPaginationExtensions.kt +++ b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/CRUDPaginationExtensions.kt @@ -3,29 +3,29 @@ package dev.inmo.micro_utils.repos.pagination import dev.inmo.micro_utils.pagination.* import dev.inmo.micro_utils.repos.ReadStandardCRUDRepo +@Deprecated("Will be removed soon due to redundancy. Can be replaced with other doForAll extensions") suspend inline fun > REPO.doForAll( @Suppress("REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE") - methodCaller: suspend REPO.(Pagination) -> PaginationResult, - block: (List) -> Unit + crossinline methodCaller: suspend REPO.(Pagination) -> PaginationResult, + crossinline block: (List) -> Unit ) { - doWithPagination { + doForAllWithNextPaging { methodCaller(it).also { block(it.results) - }.nextPageIfNotEmpty() + } } } +@Deprecated("Will be removed soon due to redundancy. Can be replaced with other doForAll extensions") suspend inline fun > REPO.doForAll( - block: (List) -> Unit -) = doForAll({ getByPagination(it) }, block) + crossinline block: (List) -> Unit +) = doForAllWithNextPaging { + getByPagination(it).also { block(it.results) } +} suspend inline fun > REPO.getAll( @Suppress("REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE") - methodCaller: suspend REPO.(Pagination) -> PaginationResult -): List { - val resultList = mutableListOf() - doForAll(methodCaller) { - resultList.addAll(it) - } - return resultList + crossinline methodCaller: suspend REPO.(Pagination) -> PaginationResult +): List = getAllWithNextPaging { + methodCaller(this, it) } diff --git a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/CommonPaginationExtensions.kt b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/CommonPaginationExtensions.kt new file mode 100644 index 00000000000..3d6b30523e7 --- /dev/null +++ b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/CommonPaginationExtensions.kt @@ -0,0 +1,67 @@ +package dev.inmo.micro_utils.repos.pagination + +import dev.inmo.micro_utils.pagination.* + +suspend fun doForAll( + initialPagination: Pagination = FirstPagePagination(), + paginationMapper: (PaginationResult) -> Pagination?, + block: suspend (Pagination) -> PaginationResult +) { + doWithPagination(initialPagination) { + block(it).let(paginationMapper) + } +} + +suspend fun doForAllWithNextPaging( + initialPagination: Pagination = FirstPagePagination(), + block: suspend (Pagination) -> PaginationResult +) { + doForAll( + initialPagination, + { it.nextPageIfNotEmpty() }, + block + ) +} + +suspend fun doAllWithCurrentPaging( + initialPagination: Pagination = FirstPagePagination(), + block: suspend (Pagination) -> PaginationResult +) { + doForAll( + initialPagination, + { it.thisPageIfNotEmpty() }, + block + ) +} + +suspend fun getAll( + initialPagination: Pagination = FirstPagePagination(), + paginationMapper: (PaginationResult) -> Pagination?, + block: suspend (Pagination) -> PaginationResult +): List { + val results = mutableListOf() + doForAll(initialPagination, paginationMapper) { + block(it).also { + results.addAll(it.results) + } + } + return results.toList() +} + +suspend fun getAllWithNextPaging( + initialPagination: Pagination = FirstPagePagination(), + block: suspend (Pagination) -> PaginationResult +): List = getAll( + initialPagination, + { it.nextPageIfNotEmpty() }, + block +) + +suspend fun getAllWithCurrentPaging( + initialPagination: Pagination = FirstPagePagination(), + block: suspend (Pagination) -> PaginationResult +): List = getAll( + initialPagination, + { it.thisPageIfNotEmpty() }, + block +) diff --git a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/KeyValuePaginationExtensions.kt b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/KeyValuePaginationExtensions.kt index 9a4b3391f2f..d4605b7dd1d 100644 --- a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/KeyValuePaginationExtensions.kt +++ b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/KeyValuePaginationExtensions.kt @@ -3,6 +3,7 @@ package dev.inmo.micro_utils.repos.pagination import dev.inmo.micro_utils.pagination.* import dev.inmo.micro_utils.repos.ReadStandardKeyValueRepo +@Deprecated("Will be removed soon due to redundancy") suspend inline fun > REPO.doForAll( @Suppress("REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE") methodCaller: suspend REPO.(Pagination) -> PaginationResult, @@ -15,17 +16,17 @@ suspend inline fun > REP } } +@Deprecated("Will be removed soon due to redundancy") suspend inline fun > REPO.doForAll( block: (List>) -> Unit ) = doForAll({ keys(it, false) }, block) suspend inline fun > REPO.getAll( @Suppress("REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE") - methodCaller: suspend REPO.(Pagination) -> PaginationResult -): List> { - val resultList = mutableListOf>() - doForAll(methodCaller) { - resultList.addAll(it) - } - return resultList + crossinline methodCaller: suspend REPO.(Pagination) -> PaginationResult +): List> = getAllWithNextPaging { + val result = methodCaller(it) + result.changeResultsUnchecked( + result.results.mapNotNull { it to (get(it) ?: return@mapNotNull null) } + ) } diff --git a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/OneToManyPaginationExtensions.kt b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/OneToManyPaginationExtensions.kt index 28d3405e595..47e43a7380c 100644 --- a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/OneToManyPaginationExtensions.kt +++ b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/OneToManyPaginationExtensions.kt @@ -3,6 +3,7 @@ package dev.inmo.micro_utils.repos.pagination import dev.inmo.micro_utils.pagination.* import dev.inmo.micro_utils.repos.ReadOneToManyKeyValueRepo +@Deprecated("Will be removed soon due to redundancy") suspend inline fun > REPO.doForAll( @Suppress("REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE") methodCaller: suspend REPO.(Pagination) -> PaginationResult, @@ -25,17 +26,19 @@ suspend inline fun > RE } } +@Deprecated("Will be removed soon due to redundancy") suspend inline fun > REPO.doForAll( block: (List>>) -> Unit ) = doForAll({ keys(it, false) }, block) suspend inline fun > REPO.getAll( @Suppress("REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE") - methodCaller: suspend REPO.(Pagination) -> PaginationResult -): List>> { - val resultList = mutableListOf>>() - doForAll(methodCaller) { - resultList.addAll(it) - } - return resultList + crossinline methodCaller: suspend REPO.(Pagination) -> PaginationResult +): List>> = getAllWithNextPaging { + val keysResult = methodCaller(it) + keysResult.changeResultsUnchecked( + keysResult.results.map { k -> + k to getAll(k) + } + ) } From 30b70e9984974790b3f42cdbfad9d53e00132679 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 29 Mar 2021 19:48:37 +0600 Subject: [PATCH 6/7] replacement of doForAll and getAll --- CHANGELOG.md | 19 +++++----- .../micro_utils/pagination/utils/DoForAll.kt | 35 +++++++++++++++++++ .../micro_utils/pagination/utils/GetAll.kt | 34 +----------------- .../inmo/micro_utils/repos/cache/KVCache.kt | 2 +- .../repos/OneToManyKeyValueRepo.kt | 2 +- .../micro_utils/repos/StandartKeyValueRepo.kt | 2 +- .../pagination/CRUDPaginationExtensions.kt | 2 ++ .../KeyValuePaginationExtensions.kt | 1 + .../OneToManyPaginationExtensions.kt | 1 + 9 files changed, 52 insertions(+), 46 deletions(-) create mode 100644 pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/utils/DoForAll.kt rename repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/CommonPaginationExtensions.kt => pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/utils/GetAll.kt (52%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c3664fe683..c2a0f57b93a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,22 +10,21 @@ * Extension `PaginationResult.thisPageIfNotEmpty` now is typed and will return `PaginationResult?` with the same generic type as income `PaginationResult` * New extension `PaginationResult.currentPageIfNotEmpty` - shortcut for `PaginationResult.thisPageIfNotEmpty` + * New common functions. They were created as replacements for currently available for more comfortable work + with repos pagination: + * `doForAll` + * `doForAllWithNextPaging` + * `doForAllWithCurrentPaging` + * `getAll` + * `getAllWithNextPaging` + * `getAllWithCurrentPaging` * `Coroutines`: * Rewrite `subscribeSafelyWithoutExceptions` * Now `subscribeSafelyWithoutExceptions` will use default handler instead of skipping * New extension `subscribeSafelySkippingExceptions` * `Repos` * New subproject `repos.cache` - this subproject will contain repos with data caching mechanisms - * `Pagination` - * New common functions. They were created as replacements for currently available for more comfortable work - with repos pagination: - * `doForAll` - * `doForAllWithNextPaging` - * `doForAllWithCurrentPaging` - * `getAll` - * `getAllWithNextPaging` - * `getAllWithCurrentPaging` - * Most old `doForAll` methods have been deprecated + * Most old `doForAll` methods have been deprecated ## 0.4.30 diff --git a/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/utils/DoForAll.kt b/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/utils/DoForAll.kt new file mode 100644 index 00000000000..7a893bb2a24 --- /dev/null +++ b/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/utils/DoForAll.kt @@ -0,0 +1,35 @@ +package dev.inmo.micro_utils.pagination.utils + +import dev.inmo.micro_utils.pagination.* + +suspend fun doForAll( + initialPagination: Pagination = FirstPagePagination(), + paginationMapper: (PaginationResult) -> Pagination?, + block: suspend (Pagination) -> PaginationResult +) { + doWithPagination(initialPagination) { + block(it).let(paginationMapper) + } +} + +suspend fun doForAllWithNextPaging( + initialPagination: Pagination = FirstPagePagination(), + block: suspend (Pagination) -> PaginationResult +) { + doForAll( + initialPagination, + { it.nextPageIfNotEmpty() }, + block + ) +} + +suspend fun doAllWithCurrentPaging( + initialPagination: Pagination = FirstPagePagination(), + block: suspend (Pagination) -> PaginationResult +) { + doForAll( + initialPagination, + { it.thisPageIfNotEmpty() }, + block + ) +} diff --git a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/CommonPaginationExtensions.kt b/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/utils/GetAll.kt similarity index 52% rename from repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/CommonPaginationExtensions.kt rename to pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/utils/GetAll.kt index 3d6b30523e7..bb670684725 100644 --- a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/CommonPaginationExtensions.kt +++ b/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/utils/GetAll.kt @@ -1,39 +1,7 @@ -package dev.inmo.micro_utils.repos.pagination +package dev.inmo.micro_utils.pagination.utils import dev.inmo.micro_utils.pagination.* -suspend fun doForAll( - initialPagination: Pagination = FirstPagePagination(), - paginationMapper: (PaginationResult) -> Pagination?, - block: suspend (Pagination) -> PaginationResult -) { - doWithPagination(initialPagination) { - block(it).let(paginationMapper) - } -} - -suspend fun doForAllWithNextPaging( - initialPagination: Pagination = FirstPagePagination(), - block: suspend (Pagination) -> PaginationResult -) { - doForAll( - initialPagination, - { it.nextPageIfNotEmpty() }, - block - ) -} - -suspend fun doAllWithCurrentPaging( - initialPagination: Pagination = FirstPagePagination(), - block: suspend (Pagination) -> PaginationResult -) { - doForAll( - initialPagination, - { it.thisPageIfNotEmpty() }, - block - ) -} - suspend fun getAll( initialPagination: Pagination = FirstPagePagination(), paginationMapper: (PaginationResult) -> Pagination?, diff --git a/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/KVCache.kt b/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/KVCache.kt index b75a741496d..a7248352446 100644 --- a/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/KVCache.kt +++ b/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/KVCache.kt @@ -1,7 +1,7 @@ package dev.inmo.micro_utils.repos.cache import dev.inmo.micro_utils.repos.* -import dev.inmo.micro_utils.repos.pagination.getAllWithNextPaging +import dev.inmo.micro_utils.pagination.utils.getAllWithNextPaging import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock diff --git a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/OneToManyKeyValueRepo.kt b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/OneToManyKeyValueRepo.kt index e899c78c2e8..001c618851b 100644 --- a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/OneToManyKeyValueRepo.kt +++ b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/OneToManyKeyValueRepo.kt @@ -1,7 +1,7 @@ package dev.inmo.micro_utils.repos import dev.inmo.micro_utils.pagination.* -import dev.inmo.micro_utils.repos.pagination.getAllWithNextPaging +import dev.inmo.micro_utils.pagination.utils.getAllWithNextPaging import kotlinx.coroutines.flow.Flow interface ReadOneToManyKeyValueRepo : Repo { diff --git a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/StandartKeyValueRepo.kt b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/StandartKeyValueRepo.kt index 7747120478a..90ad3a0b92f 100644 --- a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/StandartKeyValueRepo.kt +++ b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/StandartKeyValueRepo.kt @@ -1,7 +1,7 @@ package dev.inmo.micro_utils.repos import dev.inmo.micro_utils.pagination.* -import dev.inmo.micro_utils.repos.pagination.doAllWithCurrentPaging +import dev.inmo.micro_utils.pagination.utils.doAllWithCurrentPaging import kotlinx.coroutines.flow.Flow interface ReadStandardKeyValueRepo : Repo { diff --git a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/CRUDPaginationExtensions.kt b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/CRUDPaginationExtensions.kt index ae2a786b6c3..75478b0a2ae 100644 --- a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/CRUDPaginationExtensions.kt +++ b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/CRUDPaginationExtensions.kt @@ -1,6 +1,8 @@ package dev.inmo.micro_utils.repos.pagination import dev.inmo.micro_utils.pagination.* +import dev.inmo.micro_utils.pagination.utils.doForAllWithNextPaging +import dev.inmo.micro_utils.pagination.utils.getAllWithNextPaging import dev.inmo.micro_utils.repos.ReadStandardCRUDRepo @Deprecated("Will be removed soon due to redundancy. Can be replaced with other doForAll extensions") diff --git a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/KeyValuePaginationExtensions.kt b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/KeyValuePaginationExtensions.kt index d4605b7dd1d..bb9a75b91a7 100644 --- a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/KeyValuePaginationExtensions.kt +++ b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/KeyValuePaginationExtensions.kt @@ -1,6 +1,7 @@ package dev.inmo.micro_utils.repos.pagination import dev.inmo.micro_utils.pagination.* +import dev.inmo.micro_utils.pagination.utils.getAllWithNextPaging import dev.inmo.micro_utils.repos.ReadStandardKeyValueRepo @Deprecated("Will be removed soon due to redundancy") diff --git a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/OneToManyPaginationExtensions.kt b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/OneToManyPaginationExtensions.kt index 47e43a7380c..5e46015a060 100644 --- a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/OneToManyPaginationExtensions.kt +++ b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/OneToManyPaginationExtensions.kt @@ -1,6 +1,7 @@ package dev.inmo.micro_utils.repos.pagination import dev.inmo.micro_utils.pagination.* +import dev.inmo.micro_utils.pagination.utils.getAllWithNextPaging import dev.inmo.micro_utils.repos.ReadOneToManyKeyValueRepo @Deprecated("Will be removed soon due to redundancy") From 1b540199f0a089421321d3c15a545d5fcc6a9f35 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 29 Mar 2021 19:51:38 +0600 Subject: [PATCH 7/7] small update --- .../kotlin/dev/inmo/micro_utils/pagination/utils/DoForAll.kt | 2 +- .../kotlin/dev/inmo/micro_utils/pagination/utils/GetAll.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/utils/DoForAll.kt b/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/utils/DoForAll.kt index 7a893bb2a24..761e3b63629 100644 --- a/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/utils/DoForAll.kt +++ b/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/utils/DoForAll.kt @@ -29,7 +29,7 @@ suspend fun doAllWithCurrentPaging( ) { doForAll( initialPagination, - { it.thisPageIfNotEmpty() }, + { it.currentPageIfNotEmpty() }, block ) } diff --git a/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/utils/GetAll.kt b/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/utils/GetAll.kt index bb670684725..5ad674cb746 100644 --- a/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/utils/GetAll.kt +++ b/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/utils/GetAll.kt @@ -30,6 +30,6 @@ suspend fun getAllWithCurrentPaging( block: suspend (Pagination) -> PaginationResult ): List = getAll( initialPagination, - { it.thisPageIfNotEmpty() }, + { it.currentPageIfNotEmpty() }, block )