Stop polling queued downloads for their page list

This commit is contained in:
AntsyLich
2026-10-04 22:02:52 +06:00
parent fb8e640d69
commit 9a6dea804d
@@ -2,14 +2,13 @@ package eu.kanade.tachiyomi.data.download.model
import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.source.model.Page
import eu.kanade.tachiyomi.source.online.HttpSource import eu.kanade.tachiyomi.source.online.HttpSource
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.debounce import kotlinx.coroutines.flow.debounce
import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.emitAll import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.flowOf
import tachiyomi.domain.chapter.model.Chapter import tachiyomi.domain.chapter.model.Chapter
import tachiyomi.domain.manga.model.Manga import tachiyomi.domain.manga.model.Manga
import kotlin.time.Duration.Companion.milliseconds import kotlin.time.Duration.Companion.milliseconds
@@ -19,7 +18,13 @@ data class Download(
val manga: Manga, val manga: Manga,
val chapter: Chapter, val chapter: Chapter,
) { ) {
var pages: List<Page>? = null @Transient
private val pagesFlow = MutableStateFlow<List<Page>?>(null)
var pages: List<Page>?
get() = pagesFlow.value
set(pages) {
pagesFlow.value = pages
}
val totalProgress: Int val totalProgress: Int
get() = pages?.sumOf(Page::progress) ?: 0 get() = pages?.sumOf(Page::progress) ?: 0
@@ -39,17 +44,14 @@ data class Download(
} }
@Transient @Transient
val progressFlow = flow { val progressFlow = pagesFlow
if (pages == null) { .flatMapLatest { pages ->
emit(0) if (pages == null) {
while (pages == null) { flowOf(0)
delay(50.milliseconds) } else {
combine(pages.map(Page::progressFlow)) { it.average().toInt() }
} }
} }
val progressFlows = pages!!.map(Page::progressFlow)
emitAll(combine(progressFlows) { it.average().toInt() })
}
.distinctUntilChanged() .distinctUntilChanged()
.debounce(50.milliseconds) .debounce(50.milliseconds)