remove redundant id getter in keyvalues autocached repo

This commit is contained in:
InsanusMokrassar 2023-02-01 23:02:06 +06:00
parent 580d757be2
commit 442db122cf
3 changed files with 8 additions and 13 deletions

View File

@ -61,7 +61,7 @@ open class AutoRecacheReadKeyValueRepo<Id, RegisteredObject>(
override suspend fun get(k: Id): RegisteredObject? = actionWrapper.wrap { override suspend fun get(k: Id): RegisteredObject? = actionWrapper.wrap {
originalRepo.get(k) originalRepo.get(k)
}.getOrNull() ?.also { }.getOrNull() ?.also {
kvCache.set(idGetter(it), it) kvCache.set(k, it)
} ?: kvCache.get(k) } ?: kvCache.get(k)
override suspend fun values( override suspend fun values(

View File

@ -12,15 +12,13 @@ open class AutoRecacheKeyValuesRepo<Id, RegisteredObject>(
scope: CoroutineScope, scope: CoroutineScope,
kvCache: FullKVCache<Id, List<RegisteredObject>> = FullKVCache(), kvCache: FullKVCache<Id, List<RegisteredObject>> = FullKVCache(),
recacheDelay: Long = 60.seconds.inWholeMilliseconds, recacheDelay: Long = 60.seconds.inWholeMilliseconds,
actionWrapper: ActionWrapper = ActionWrapper.Direct, actionWrapper: ActionWrapper = ActionWrapper.Direct
idGetter: (RegisteredObject) -> Id
) : AutoRecacheReadKeyValuesRepo<Id, RegisteredObject> ( ) : AutoRecacheReadKeyValuesRepo<Id, RegisteredObject> (
originalRepo, originalRepo,
scope, scope,
kvCache, kvCache,
recacheDelay, recacheDelay,
actionWrapper, actionWrapper
idGetter
), ),
WriteKeyValuesRepo<Id, RegisteredObject> by AutoRecacheWriteKeyValuesRepo(originalRepo, scope, kvCache), WriteKeyValuesRepo<Id, RegisteredObject> by AutoRecacheWriteKeyValuesRepo(originalRepo, scope, kvCache),
KeyValuesRepo<Id, RegisteredObject> { KeyValuesRepo<Id, RegisteredObject> {
@ -30,9 +28,8 @@ open class AutoRecacheKeyValuesRepo<Id, RegisteredObject>(
scope: CoroutineScope, scope: CoroutineScope,
originalCallTimeoutMillis: Long, originalCallTimeoutMillis: Long,
kvCache: FullKVCache<Id, List<RegisteredObject>> = FullKVCache(), kvCache: FullKVCache<Id, List<RegisteredObject>> = FullKVCache(),
recacheDelay: Long = 60.seconds.inWholeMilliseconds, recacheDelay: Long = 60.seconds.inWholeMilliseconds
idGetter: (RegisteredObject) -> Id ) : this(originalRepo, scope, kvCache, recacheDelay, ActionWrapper.Timeouted(originalCallTimeoutMillis))
) : this(originalRepo, scope, kvCache, recacheDelay, ActionWrapper.Timeouted(originalCallTimeoutMillis), idGetter)
override suspend fun clearWithValue(v: RegisteredObject) { override suspend fun clearWithValue(v: RegisteredObject) {
super.clearWithValue(v) super.clearWithValue(v)

View File

@ -27,8 +27,7 @@ open class AutoRecacheReadKeyValuesRepo<Id, RegisteredObject>(
protected val scope: CoroutineScope, protected val scope: CoroutineScope,
protected val kvCache: FullKVCache<Id, List<RegisteredObject>> = FullKVCache(), protected val kvCache: FullKVCache<Id, List<RegisteredObject>> = FullKVCache(),
protected val recacheDelay: Long = 60.seconds.inWholeMilliseconds, protected val recacheDelay: Long = 60.seconds.inWholeMilliseconds,
protected val actionWrapper: ActionWrapper = ActionWrapper.Direct, protected val actionWrapper: ActionWrapper = ActionWrapper.Direct
protected val idGetter: (RegisteredObject) -> Id
) : ReadKeyValuesRepo<Id, RegisteredObject>, FallbackCacheRepo { ) : ReadKeyValuesRepo<Id, RegisteredObject>, FallbackCacheRepo {
val autoUpdateJob = scope.launch { val autoUpdateJob = scope.launch {
while (isActive) { while (isActive) {
@ -43,9 +42,8 @@ open class AutoRecacheReadKeyValuesRepo<Id, RegisteredObject>(
scope: CoroutineScope, scope: CoroutineScope,
originalCallTimeoutMillis: Long, originalCallTimeoutMillis: Long,
kvCache: FullKVCache<Id, List<RegisteredObject>> = FullKVCache(), kvCache: FullKVCache<Id, List<RegisteredObject>> = FullKVCache(),
recacheDelay: Long = 60.seconds.inWholeMilliseconds, recacheDelay: Long = 60.seconds.inWholeMilliseconds
idGetter: (RegisteredObject) -> Id ) : this(originalRepo, scope, kvCache, recacheDelay, ActionWrapper.Timeouted(originalCallTimeoutMillis))
) : this(originalRepo, scope, kvCache, recacheDelay, ActionWrapper.Timeouted(originalCallTimeoutMillis), idGetter)
protected suspend fun actualizeAll(): Result<Unit> { protected suspend fun actualizeAll(): Result<Unit> {
return runCatchingSafely { return runCatchingSafely {