add check of emptiness in map reslozations of KV/KVs repos

This commit is contained in:
InsanusMokrassar 2024-08-06 14:07:57 +06:00
parent bf293a8f8f
commit 9f2f0de0c4
2 changed files with 6 additions and 0 deletions

View File

@ -102,11 +102,13 @@ class WriteMapKeyValueRepo<Key, Value>(
constructor(map: MutableMap<Key, Value> = mutableMapOf()) : this(map, SmartRWLocker())
override suspend fun set(toSet: Map<Key, Value>) {
if (toSet.isEmpty()) return
locker.withWriteLock { map.putAll(toSet) }
toSet.forEach { (k, v) -> _onNewValue.emit(k to v) }
}
override suspend fun unset(toUnset: List<Key>) {
if (toUnset.isEmpty()) return
locker.withWriteLock {
toUnset.mapNotNull { k ->
map.remove(k) ?.let { _ -> k }

View File

@ -124,6 +124,8 @@ class MapWriteKeyValuesRepo<Key, Value>(
}
override suspend fun set(toSet: Map<Key, List<Value>>) {
if (toSet.isEmpty()) return
locker.withWriteLock {
map.putAll(
toSet.mapValues { it.value.toMutableList() }
@ -137,6 +139,8 @@ class MapWriteKeyValuesRepo<Key, Value>(
}
override suspend fun remove(toRemove: Map<Key, List<Value>>) {
if (toRemove.isEmpty()) return
val removed = mutableListOf<Pair<Key, Value>>()
val cleared = mutableListOf<Key>()
locker.withWriteLock {