mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-12-18 14:47:15 +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.utils.doForAllWithNextPaging
|
||||
import dev.inmo.micro_utils.pagination.utils.getAllByWithNextPaging
|
||||
import dev.inmo.micro_utils.repos.ReadCRUDRepo
|
||||
import dev.inmo.micro_utils.repos.ReadKeyValueRepo
|
||||
import dev.inmo.micro_utils.repos.ReadKeyValuesRepo
|
||||
import dev.inmo.micro_utils.repos.cache.cache.KVCache
|
||||
import dev.inmo.micro_utils.repos.pagination.getAll
|
||||
import dev.inmo.micro_utils.repos.set
|
||||
|
||||
suspend inline fun <K, V> KVCache<K, V>.actualizeAll(
|
||||
getAll: () -> Map<K, V>
|
||||
) {
|
||||
clear()
|
||||
set(
|
||||
getAll().also {
|
||||
clear()
|
||||
@ -22,56 +23,25 @@ suspend inline fun <K, V> KVCache<K, V>.actualizeAll(
|
||||
suspend inline fun <K, V> KVCache<K, V>.actualizeAll(
|
||||
repo: ReadKeyValueRepo<K, V>
|
||||
) {
|
||||
var cleared = false
|
||||
val count = repo.count().takeIf { it < Int.MAX_VALUE } ?.toInt() ?: Int.MAX_VALUE
|
||||
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 } }
|
||||
)
|
||||
}
|
||||
actualizeAll {
|
||||
repo.getAll { keys(it) }.toMap()
|
||||
}
|
||||
}
|
||||
|
||||
suspend inline fun <K, V> KVCache<K, List<V>>.actualizeAll(
|
||||
repo: ReadKeyValuesRepo<K, V>
|
||||
) {
|
||||
var cleared = false
|
||||
val count = repo.count().takeIf { it < Int.MAX_VALUE } ?.toInt() ?: Int.MAX_VALUE
|
||||
val initPagination = FirstPagePagination(count)
|
||||
doForAllWithNextPaging(initPagination) {
|
||||
keys(it).also {
|
||||
if (!cleared) {
|
||||
clear()
|
||||
cleared = true
|
||||
}
|
||||
set(
|
||||
it.results.associateWith { k -> repo.getAll(k) }
|
||||
)
|
||||
}
|
||||
actualizeAll {
|
||||
repo.getAll { keys(it) }.toMap()
|
||||
}
|
||||
}
|
||||
|
||||
suspend inline fun <K, V> KVCache<K, V>.actualizeAll(
|
||||
repo: ReadCRUDRepo<V, K>
|
||||
) {
|
||||
var cleared = false
|
||||
val count = repo.count().takeIf { it < Int.MAX_VALUE } ?.toInt() ?: Int.MAX_VALUE
|
||||
val initPagination = FirstPagePagination(count)
|
||||
doForAllWithNextPaging(initPagination) {
|
||||
keys(it).also {
|
||||
if (!cleared) {
|
||||
clear()
|
||||
cleared = true
|
||||
}
|
||||
set(
|
||||
it.results.mapNotNull { k -> repo.getById(k) ?.let { k to it } }
|
||||
)
|
||||
}
|
||||
actualizeAll {
|
||||
repo.getAllByWithNextPaging {
|
||||
getIdsByPagination(it)
|
||||
}.mapNotNull { it to (repo.getById(it) ?: return@mapNotNull null) }.toMap()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user