Make retry in reader redownload image (#3089)

This commit is contained in:
AntsyLich
2026-03-19 16:40:49 +06:00
committed by GitHub
parent 99edfbe4a8
commit d4b88b13b8
2 changed files with 20 additions and 8 deletions
@@ -47,11 +47,16 @@ internal class HttpPageLoader(
scope.launchIO {
flow {
while (true) {
emit(runInterruptible { queue.take() }.page)
emit(runInterruptible { queue.take() })
}
}
.filter { it.status == Page.State.Queue }
.collect(::internalLoadPage)
.filter { it.page.status == Page.State.Queue }
.collect {
internalLoadPage(
page = it.page,
force = it.priority == PriorityPage.RETRY,
)
}
}
}
@@ -94,7 +99,7 @@ internal class HttpPageLoader(
val queuedPages = mutableListOf<PriorityPage>()
if (page.status == Page.State.Queue) {
queuedPages += PriorityPage(page, 1).also { queue.offer(it) }
queuedPages += PriorityPage(page, PriorityPage.DEFAULT).also { queue.offer(it) }
}
queuedPages += preloadNextPages(page, preloadSize)
@@ -116,7 +121,7 @@ internal class HttpPageLoader(
if (page.status is Page.State.Error) {
page.status = Page.State.Queue
}
queue.offer(PriorityPage(page, 2))
queue.offer(PriorityPage(page, PriorityPage.RETRY))
}
override fun recycle() {
@@ -154,7 +159,7 @@ internal class HttpPageLoader(
.subList(pageIndex + 1, min(pageIndex + 1 + amount, pages.size))
.mapNotNull {
if (it.status == Page.State.Queue) {
PriorityPage(it, 0).apply { queue.offer(this) }
PriorityPage(it, PriorityPage.ADJACENT).apply { queue.offer(this) }
} else {
null
}
@@ -167,7 +172,7 @@ internal class HttpPageLoader(
*
* @param page the page whose source image has to be downloaded.
*/
private suspend fun internalLoadPage(page: ReaderPage) {
private suspend fun internalLoadPage(page: ReaderPage, force: Boolean) {
try {
if (page.imageUrl.isNullOrEmpty()) {
page.status = Page.State.LoadPage
@@ -175,7 +180,7 @@ internal class HttpPageLoader(
}
val imageUrl = page.imageUrl!!
if (!chapterCache.isImageInCache(imageUrl)) {
if (force || !chapterCache.isImageInCache(imageUrl)) {
page.status = Page.State.DownloadImage
val imageResponse = source.getImage(page)
chapterCache.putImageToCache(imageUrl, imageResponse)
@@ -202,6 +207,10 @@ private class PriorityPage(
) : Comparable<PriorityPage> {
companion object {
private val idGenerator = AtomicInt(0)
const val RETRY = 2
const val DEFAULT = 1
const val ADJACENT = 0
}
private val identifier = idGenerator.incrementAndFetch()