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 c79c20033c
commit 89ce3c9f82
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 {