-
Notifications
You must be signed in to change notification settings - Fork 185
Description
Steps to reproduce
If a plugin source is flaky Tachiyomi cannot recover very well.
Expected behavior
I'm not great at kotlin so I'll show some pseudocode.
Related to #1434 but I am proposing a solution instead of just noting that it's a problem.
I'm not really sure what the current algorithm is, only that it's flaky.
A robust downloading algorithm would be as follows.
class MangaChapter
{
//..
Page[] undownloadedPages ;
bool hasUndownloadedPages => undownloadedPages.Count > 0
void downloadPagesChronologically(){ /*...*/}
}
class Manga
{
void downloadIfNeeded()
{
MangaChapter[] cl = getUnreadChaptersAfterReadMarker(preferences.preloadChapterCount);
if(c.hasUndlownloadedPages)
{
downloadManager.downloadPagesChronologically(cl);
}
}
}Schedule a recurring job to fill chapters, it's not exactly light since it has to query the library, but it can also end pretty quickly once it finishs polling all managa for if it needs pages filled.
Schedule this at a user define time say avery 60 seconds and also it's fine to run in the background under some conditions.
void downloadManagerJob()
{
Manga[] ml = getMangaInReadHistroyOrLibrary()
foreach( m : ml )
{
m.downloadIfNeeded();
if(!shouldContinueDownloading()) break; //check if we left wifi or are on battery or whatever
}
scheduleJob(downloadManagerJob); //We completed so reschedule us as background or foreground job
}Basically the download job is always scheduled and always checked if the all of the preload chapters of all of the manga are downloaded.
Then you have to consider the manga I am currently reading, because you might want to preempt whatever is scheduled with manga chapters I am going to need imminently.
void didResumeReadingManga(Manga m,MangaChapter c)
{
preload(c);
}
void didAdvancePageViewingManga(Manga m, MangaChapter c)
{
preload(c);
}
void preload(MangaChapter m)
{
//Create the next chapter if necessary and emplace at top of queue.
//Or if it is in the queue move it to the top pushing down whatever is currently at top
//Since this triggers multiple times as you read it might end immediately because
//all pages for next chapter are already in cache
// if the web server is flaky this gives the download manager time to download the incomplete chapter.
DownloadManager.PreemptWithChapter(c.nextChapter);
//try to fill any blank pages for the chapter I've started reading
//if no such pages no harm this will just finish instantly
//Again put it at the top of the queue.
//NOTE: The ordering means that at the end of this function the current chapter is at the top of the queue then the next one.
DownloadManager.PreemptWithChapter(c);
}
### Actual behavior
Sometimes images just seems to not be loaded, and I have to wait, or click the download button manually on the chapters I will soon be reading for a smooth reading experience, even though Tachiyomi has has literally all night to download chapters it could easily predict i would be interested in reading.
### Crash logs
_No response_
### TachiyomiSY version
1.12.0
### Android version
15
### Device
samsung SM-P620
### Other details
_No response_
### Acknowledgements
- [x] I have searched the existing issues and this is a new ticket, **NOT** a duplicate or related to another open or closed issue.
- [x] I have written a short but informative title.
- [x] I have gone through the [FAQ](https://mihon.app/docs/faq/general) and [troubleshooting guide](https://mihon.app/docs/guides/troubleshooting/).
- [x] I have updated the app to version **[1.12.0](https://github.com/jobobby04/tachiyomisy/releases/latest)**.
- [x] I have filled out all of the requested information in this form, including specific version numbers.
- [x] I understand that **Mihon does not have or fix any extensions**, and I **will not receive help** for any issues related to sources or extensions.