Make retry in reader redownload image (#3089)
This commit is contained in:
@@ -11,6 +11,9 @@ The format is a modified version of [Keep a Changelog](https://keepachangelog.co
|
||||
- `Other` - for technical stuff.
|
||||
|
||||
## [Unreleased]
|
||||
### Changed
|
||||
- Retry in reader now redownloads image ([@AntsyLich](https://github.com/AntsyLich)) ([#3089](https://github.com/mihonapp/mihon/pull/3089))
|
||||
|
||||
### Improved
|
||||
- Rework internals for better performance ([@Lolle2000la](https://github.com/Lolle2000la)) ([#2955](https://github.com/mihonapp/mihon/pull/2955))
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user