mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-11-17 13:53:49 +00:00
fixes in actualizeAll
This commit is contained in:
parent
6142022283
commit
2162e83bce
@ -2,16 +2,17 @@ package dev.inmo.micro_utils.repos.cache.util
|
|||||||
|
|
||||||
import dev.inmo.micro_utils.pagination.FirstPagePagination
|
import dev.inmo.micro_utils.pagination.FirstPagePagination
|
||||||
import dev.inmo.micro_utils.pagination.utils.doForAllWithNextPaging
|
import dev.inmo.micro_utils.pagination.utils.doForAllWithNextPaging
|
||||||
|
import dev.inmo.micro_utils.pagination.utils.getAllByWithNextPaging
|
||||||
import dev.inmo.micro_utils.repos.ReadCRUDRepo
|
import dev.inmo.micro_utils.repos.ReadCRUDRepo
|
||||||
import dev.inmo.micro_utils.repos.ReadKeyValueRepo
|
import dev.inmo.micro_utils.repos.ReadKeyValueRepo
|
||||||
import dev.inmo.micro_utils.repos.ReadKeyValuesRepo
|
import dev.inmo.micro_utils.repos.ReadKeyValuesRepo
|
||||||
import dev.inmo.micro_utils.repos.cache.cache.KVCache
|
import dev.inmo.micro_utils.repos.cache.cache.KVCache
|
||||||
|
import dev.inmo.micro_utils.repos.pagination.getAll
|
||||||
import dev.inmo.micro_utils.repos.set
|
import dev.inmo.micro_utils.repos.set
|
||||||
|
|
||||||
suspend inline fun <K, V> KVCache<K, V>.actualizeAll(
|
suspend inline fun <K, V> KVCache<K, V>.actualizeAll(
|
||||||
getAll: () -> Map<K, V>
|
getAll: () -> Map<K, V>
|
||||||
) {
|
) {
|
||||||
clear()
|
|
||||||
set(
|
set(
|
||||||
getAll().also {
|
getAll().also {
|
||||||
clear()
|
clear()
|
||||||
@ -22,56 +23,25 @@ suspend inline fun <K, V> KVCache<K, V>.actualizeAll(
|
|||||||
suspend inline fun <K, V> KVCache<K, V>.actualizeAll(
|
suspend inline fun <K, V> KVCache<K, V>.actualizeAll(
|
||||||
repo: ReadKeyValueRepo<K, V>
|
repo: ReadKeyValueRepo<K, V>
|
||||||
) {
|
) {
|
||||||
var cleared = false
|
actualizeAll {
|
||||||
val count = repo.count().takeIf { it < Int.MAX_VALUE } ?.toInt() ?: Int.MAX_VALUE
|
repo.getAll { keys(it) }.toMap()
|
||||||
val initPagination = FirstPagePagination(count)
|
|
||||||
doForAllWithNextPaging(initPagination) {
|
|
||||||
keys(it).also {
|
|
||||||
if (!cleared) {
|
|
||||||
clear()
|
|
||||||
cleared = true
|
|
||||||
}
|
|
||||||
set(
|
|
||||||
it.results.mapNotNull { k -> repo.get(k) ?.let { k to it } }
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend inline fun <K, V> KVCache<K, List<V>>.actualizeAll(
|
suspend inline fun <K, V> KVCache<K, List<V>>.actualizeAll(
|
||||||
repo: ReadKeyValuesRepo<K, V>
|
repo: ReadKeyValuesRepo<K, V>
|
||||||
) {
|
) {
|
||||||
var cleared = false
|
actualizeAll {
|
||||||
val count = repo.count().takeIf { it < Int.MAX_VALUE } ?.toInt() ?: Int.MAX_VALUE
|
repo.getAll { keys(it) }.toMap()
|
||||||
val initPagination = FirstPagePagination(count)
|
|
||||||
doForAllWithNextPaging(initPagination) {
|
|
||||||
keys(it).also {
|
|
||||||
if (!cleared) {
|
|
||||||
clear()
|
|
||||||
cleared = true
|
|
||||||
}
|
|
||||||
set(
|
|
||||||
it.results.associateWith { k -> repo.getAll(k) }
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend inline fun <K, V> KVCache<K, V>.actualizeAll(
|
suspend inline fun <K, V> KVCache<K, V>.actualizeAll(
|
||||||
repo: ReadCRUDRepo<V, K>
|
repo: ReadCRUDRepo<V, K>
|
||||||
) {
|
) {
|
||||||
var cleared = false
|
actualizeAll {
|
||||||
val count = repo.count().takeIf { it < Int.MAX_VALUE } ?.toInt() ?: Int.MAX_VALUE
|
repo.getAllByWithNextPaging {
|
||||||
val initPagination = FirstPagePagination(count)
|
getIdsByPagination(it)
|
||||||
doForAllWithNextPaging(initPagination) {
|
}.mapNotNull { it to (repo.getById(it) ?: return@mapNotNull null) }.toMap()
|
||||||
keys(it).also {
|
|
||||||
if (!cleared) {
|
|
||||||
clear()
|
|
||||||
cleared = true
|
|
||||||
}
|
|
||||||
set(
|
|
||||||
it.results.mapNotNull { k -> repo.getById(k) ?.let { k to it } }
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user