[优化] 继续优化书架性能
This commit is contained in:
1 parent
d1ebcd3bf0
commit
d029f3016e
2 files changed
+7
-2
No files matched your search
@@ -1,9 +1,11 @@
|
|||||||
package io.legado.app.ui.main.bookshelf
|
package io.legado.app.ui.main.bookshelf
|
||||||
|
|
||||||
|
import androidx.compose.runtime.Stable
|
||||||
import io.legado.app.constant.BookType
|
import io.legado.app.constant.BookType
|
||||||
import io.legado.app.data.entities.Book
|
import io.legado.app.data.entities.Book
|
||||||
import kotlin.math.max
|
import kotlin.math.max
|
||||||
|
|
||||||
|
@Stable
|
||||||
data class BookShelfItem(
|
data class BookShelfItem(
|
||||||
val bookUrl: String,
|
val bookUrl: String,
|
||||||
val name: String,
|
val name: String,
|
||||||
|
|||||||
@@ -122,7 +122,10 @@ class BookshelfViewModel(
|
|||||||
val allGroupsFlow: StateFlow<List<BookGroup>> = bookGroupRepository.flowAll()
|
val allGroupsFlow: StateFlow<List<BookGroup>> = bookGroupRepository.flowAll()
|
||||||
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), emptyList())
|
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), emptyList())
|
||||||
|
|
||||||
private val allBooksFlow = appDb.bookDao.flowBookShelf().flowOn(Dispatchers.Default)
|
private val allBooksFlow = appDb.bookDao.flowBookShelf()
|
||||||
|
.map { list -> list.map { it.toBookShelfItem() } }
|
||||||
|
.distinctUntilChanged()
|
||||||
|
.flowOn(Dispatchers.Default)
|
||||||
|
|
||||||
@OptIn(ExperimentalCoroutinesApi::class)
|
@OptIn(ExperimentalCoroutinesApi::class)
|
||||||
val booksFlow = combine(groupIdFlow, refreshTrigger) { groupId, _ -> groupId }
|
val booksFlow = combine(groupIdFlow, refreshTrigger) { groupId, _ -> groupId }
|
||||||
@@ -132,7 +135,7 @@ class BookshelfViewModel(
|
|||||||
list.map { it.toBookShelfItem() },
|
list.map { it.toBookShelfItem() },
|
||||||
groupsFlow.value.find { it.groupId == groupId })
|
groupsFlow.value.find { it.groupId == groupId })
|
||||||
}
|
}
|
||||||
}.flowOn(Dispatchers.Default)
|
}.distinctUntilChanged().flowOn(Dispatchers.Default)
|
||||||
|
|
||||||
private val groupPreviewsFlow =
|
private val groupPreviewsFlow =
|
||||||
combine(groupsFlow, allBooksFlow, refreshTrigger) { groups, allBooks, _ ->
|
combine(groupsFlow, allBooksFlow, refreshTrigger) { groups, allBooks, _ ->
|
||||||
|
|||||||
Reference in new issue
Block a user