From c9822a491b1600f99fb2a50308c26096eafa11f0 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 5 Sep 2022 15:07:33 +0600 Subject: [PATCH] WriteCRUDCacheRepo subscribtions and changeResultsUnchecked(Pagination) --- CHANGELOG.md | 6 ++++++ .../dev/inmo/micro_utils/pagination/PaginationResult.kt | 8 ++++++++ .../dev/inmo/micro_utils/repos/cache/CRUDCacheRepo.kt | 8 ++++++++ 3 files changed, 22 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 19e04f00045..dc1baf3979a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ ## 0.12.7 +* `Repos`: + * `Cache`: + * Force `WriteCRUDCacheRepo` to subscribe on new and updated objects of parent repo +* `Pagination`: + * New function `changeResultsUnchecked(Pagination)` + ## 0.12.6 * `MimeeTypes>`: diff --git a/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/PaginationResult.kt b/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/PaginationResult.kt index 6a62cf5bdfa..3abd96bc9b5 100644 --- a/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/PaginationResult.kt +++ b/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/PaginationResult.kt @@ -48,6 +48,14 @@ data class PaginationResult( } fun emptyPaginationResult() = PaginationResult(0, 0, emptyList(), 0L) +fun emptyPaginationResult( + basePagination: Pagination +) = PaginationResult( + basePagination.page, + basePagination.size, + emptyList(), + 0L +) /** * @return New [PaginationResult] with [data] without checking of data sizes equality diff --git a/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/CRUDCacheRepo.kt b/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/CRUDCacheRepo.kt index 28ab069b0ff..413e116cd92 100644 --- a/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/CRUDCacheRepo.kt +++ b/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/CRUDCacheRepo.kt @@ -33,6 +33,14 @@ open class WriteCRUDCacheRepo( override val updatedObjectsFlow: Flow by parentRepo::updatedObjectsFlow override val deletedObjectsIdsFlow: Flow by parentRepo::deletedObjectsIdsFlow + val createdObjectsFlowJob = parentRepo.newObjectsFlow.onEach { + kvCache.set(idGetter(it), it) + }.launchIn(scope) + + val updatedObjectsFlowJob = parentRepo.updatedObjectsFlow.onEach { + kvCache.set(idGetter(it), it) + }.launchIn(scope) + val deletedObjectsFlowJob = parentRepo.deletedObjectsIdsFlow.onEach { kvCache.unset(it) }.launchIn(scope)