mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2025-09-16 05:52:22 +00:00
ReadKeyValuesRepo#removeWithValue
This commit is contained in:
@@ -7,6 +7,7 @@ import dev.inmo.micro_utils.pagination.utils.doForAllWithNextPaging
|
||||
import dev.inmo.micro_utils.repos.WriteKeyValuesRepo
|
||||
import dev.inmo.micro_utils.repos.cache.cache.FullKVCache
|
||||
import dev.inmo.micro_utils.repos.cache.FallbackCacheRepo
|
||||
import dev.inmo.micro_utils.repos.pagination.maxPagePagination
|
||||
import dev.inmo.micro_utils.repos.set
|
||||
import dev.inmo.micro_utils.repos.unset
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
@@ -50,7 +51,7 @@ open class AutoRecacheWriteKeyValuesRepo<Id, RegisteredObject>(
|
||||
|
||||
override suspend fun clearWithValue(v: RegisteredObject) {
|
||||
originalRepo.clearWithValue(v)
|
||||
doForAllWithNextPaging(FirstPagePagination(kvCache.count().takeIf { it < Int.MAX_VALUE } ?.toInt() ?: Int.MAX_VALUE)) {
|
||||
doForAllWithNextPaging(kvCache.maxPagePagination()) {
|
||||
kvCache.keys(it).also {
|
||||
it.results.forEach { id ->
|
||||
kvCache.get(id) ?.takeIf { it.contains(v) } ?.let {
|
||||
@@ -73,6 +74,19 @@ open class AutoRecacheWriteKeyValuesRepo<Id, RegisteredObject>(
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun removeWithValue(v: RegisteredObject) {
|
||||
originalRepo.removeWithValue(v)
|
||||
doForAllWithNextPaging(kvCache.maxPagePagination()) {
|
||||
kvCache.keys(it).also {
|
||||
it.results.forEach { id ->
|
||||
kvCache.get(id) ?.takeIf { it.contains(v) } ?.let {
|
||||
kvCache.set(id, it - v)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun add(toAdd: Map<Id, List<RegisteredObject>>) {
|
||||
originalRepo.add(toAdd)
|
||||
toAdd.forEach { (k, v) ->
|
||||
|
@@ -157,6 +157,10 @@ open class FullKeyValuesCacheRepo<Key,Value>(
|
||||
override suspend fun invalidate() {
|
||||
kvCache.actualizeAll(parentRepo)
|
||||
}
|
||||
|
||||
override suspend fun removeWithValue(v: Value) {
|
||||
super<FullWriteKeyValuesCacheRepo>.removeWithValue(v)
|
||||
}
|
||||
}
|
||||
|
||||
fun <Key, Value> KeyValuesRepo<Key, Value>.fullyCached(
|
||||
|
Reference in New Issue
Block a user