mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-15 05:27:28 +01:00
Clean up download ahead logic
- Remove redundant chapter sorting logic when fetching next chapter(s) - Remove redundant download queue checks (it'll handle already queued or downloaded items) - Trigger download ahead when read >= 25% of chapter rather than 20% - Rely on download cache when checking if next chapter is downloaded to avoid jank (fixes #8328)
This commit is contained in:
@@ -244,6 +244,10 @@ class Downloader(
|
||||
* @param autoStart whether to start the downloader after enqueing the chapters.
|
||||
*/
|
||||
fun queueChapters(manga: Manga, chapters: List<Chapter>, autoStart: Boolean) = launchIO {
|
||||
if (chapters.isEmpty()) {
|
||||
return@launchIO
|
||||
}
|
||||
|
||||
val source = sourceManager.get(manga.source) as? HttpSource ?: return@launchIO
|
||||
val wasEmpty = queue.isEmpty()
|
||||
// Called in background thread, the operation can be slow with SAF.
|
||||
|
||||
@@ -415,8 +415,7 @@ class LibraryUpdateService(
|
||||
private fun downloadChapters(manga: Manga, chapters: List<Chapter>) {
|
||||
// We don't want to start downloading while the library is updating, because websites
|
||||
// may don't like it and they could ban the user.
|
||||
val dbChapters = chapters.map { it.toDbChapter() }
|
||||
downloadManager.downloadChapters(manga, dbChapters, false)
|
||||
downloadManager.downloadChapters(manga, chapters.map { it.toDbChapter() }, false)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -271,11 +271,9 @@ class NotificationReceiver : BroadcastReceiver() {
|
||||
*/
|
||||
private fun downloadChapters(chapterUrls: Array<String>, mangaId: Long) {
|
||||
launchIO {
|
||||
val manga = getManga.await(mangaId)
|
||||
val manga = getManga.await(mangaId) ?: return@launchIO
|
||||
val chapters = chapterUrls.mapNotNull { getChapter.await(it, mangaId)?.toDbChapter() }
|
||||
if (manga != null && chapters.isNotEmpty()) {
|
||||
downloadManager.downloadChapters(manga, chapters)
|
||||
}
|
||||
downloadManager.downloadChapters(manga, chapters)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user