This commit is contained in:
InsanusMokrassar 2023-01-18 23:39:56 +06:00
parent 2e7a1b83c5
commit dc5833c407
3 changed files with 8 additions and 4 deletions

View File

@ -43,7 +43,7 @@ class CachedPostsRepo(
return null
}
override suspend fun getPostCreationTime(postId: PostId): DateTime? = kvCache.get(postId) ?.created
override suspend fun getPostCreationTime(postId: PostId): DateTime? = getById(postId) ?.created
override suspend fun getFirstMessageInfo(postId: PostId): PostContentInfo? = kvCache.get(postId) ?.content ?.firstOrNull()
override suspend fun getFirstMessageInfo(postId: PostId): PostContentInfo? = getById(postId) ?.content ?.firstOrNull()
}

View File

@ -1,6 +1,9 @@
package dev.inmo.plaguposter.ratings.source.buttons
import com.soywiz.klock.DateFormat
import dev.inmo.kslog.common.TagLogger
import dev.inmo.kslog.common.d
import dev.inmo.kslog.common.i
import dev.inmo.micro_utils.coroutines.runCatchingSafely
import dev.inmo.micro_utils.pagination.FirstPagePagination
import dev.inmo.micro_utils.pagination.Pagination
@ -63,6 +66,7 @@ suspend fun RatingsRepo.buildRatingButtons(
postCreationTimeFormat: DateFormat = defaultPostCreationTimeFormat
): InlineKeyboardMarkup {
val postsByRatings = getPosts(rating .. rating, true).keys.paginate(pagination)
TagLogger("RatingsButtonsBuilder").i { postsByRatings.results }
return inlineKeyboard {
if (postsByRatings.pagesNumber > 1) {
row {
@ -75,7 +79,7 @@ suspend fun RatingsRepo.buildRatingButtons(
}
}
}
postsByRatings.results.chunked(rowSize).map {
postsByRatings.results.chunked(rowSize).forEach {
row {
it.forEach { postId ->
val firstMessageInfo = postsRepo.getFirstMessageInfo(postId) ?: return@forEach

View File

@ -24,7 +24,7 @@ class CachedRatingsRepo(
doForAllWithNextPaging {
kvCache.keys(it).also {
it.results.forEach {
val rating = kvCache.get(it) ?: return@forEach
val rating = get(it) ?: return@forEach
if (it !in exclude && rating in range) {
result[it] = rating
}