Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incremental loading and filter system for local source #437

Draft
wants to merge 20 commits into
base: main
Choose a base branch
from

Conversation

Shamicen
Copy link
Contributor

@Shamicen Shamicen commented Feb 21, 2024

Closes #365
Fixes #397

I implemented my old Tachiyomi PR in Mihon.

New features:

  • Local Source manga now load in chunks of 10 instead of having to wait for all Manga to load.
  • Manga now get loaded with Metadata applied.
  • Manga can now be filtered.

Caveats:

  • Filters can only be applied to manga that have already loaded.
  • Order By is only available once all manga have loaded.
  • Adding new Manga to Local Source requires an app restart. New Manga can be added without restarting the app.
  • To update the filters the user has to press the reset button.

Loading times could be significantly improved by using ParallelStreams but this may hurt general app performance on low power devices.

@AntsyLich
Copy link
Member

Can we have the local source items indexed separately similar to download index and use filesystem observer to detect changes (FileObserver for android).

@Shamicen
Copy link
Contributor Author

Shamicen commented Feb 25, 2024

I don't really understand what you mean by indexed separately. If this about adding new files to LocalSource while the app is running we could achieve that with a FileObserver and adding the new manga to the end of the list, but as far as i can see FileObserver needs to have file access and i don't think this is possible with Scoped Storage.

If you mean caching LocalSource manga so we do not have to read the ComicInfo files every time then that would probably not be worth it since the bulk of the loading time comes from the cover files I forgot since it was so long ago but we already use metadata saved in the db to avoid re-scanning when available. The problem with the current implementation is that updates to the ComicInfo file will not get reflected. I also added a lastModified value to SManga if we also implement that value in Manga as lastModifiedLocal for example and push it to the db then we can simply compare the values and only re-scan if they do not match.

@AntsyLich
Copy link
Member

Right forgot about SAF. Lemme think about this for a bit.

@Shamicen
Copy link
Contributor Author

Shamicen commented Feb 26, 2024

I now implemented logic, to only re-scan ComicInfo files if the manga directory was modified.

@Shamicen
Copy link
Contributor Author

I added support for adding new manga while the app is running

@AntsyLich
Copy link
Member

Cache local source entry metadata in the database. Reindex them on MainActivity.onResume(). No need to make append new manga to the end users can just search again. You may want to tweak the caching process to make it as efficient as possible. Like if a folder was already cached before compare their modification time and stuff

@Shamicen Shamicen force-pushed the local_source_incremental_loading branch from 4890b1a to b6a53ec Compare February 17, 2025 00:12
@Shamicen
Copy link
Contributor Author

Shamicen commented Feb 17, 2025

Cache local source entry metadata in the database.

I already do cache the metadata in the database

Reindex them on MainActivity.onResume().

Why do you want to index them at that point? currently loading the metadata for an entire page (10 Manga) from the db takes around 0.017s. I do not think we gain anything from indexing them at app start. This would also lead to chunk sizes becoming irregular if a user removed or added manga to their local source directory.

No need to make append new manga to the end users can just search again.

Simply searching again won't help here. When the Local Source class is initialized, it loads all the directories (manga chunks) at that time. After all manga have been loaded once, I append any new directories that have been added to the Local Source directory since app launch to the manga chunks. If we remove this functionality, an app restart would be necessary to add new manga to Local Source.

You may want to tweak the caching process to make it as efficient as possible. Like if a folder was already cached before compare their modification time and stuff

I already do this it only reads the ComicInfo file from disk if the manga has not been cached yet or if it was modified.

How about testing the current version once to compare the initial uncached load with subsequent cached loads? If it still loads to slow I can try to optimize it further. However, if I recall correctly, most of the remaining page load time was spent outside the functions I implemented.

I also discovered a bug where opening Local Source throws an error if it is empty. I will investigate this issue over the coming weekend, and for now, I will convert this PR to a draft.

@Shamicen Shamicen marked this pull request as draft February 17, 2025 01:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot search using tags on local source Make local sources load in chunks like other extensions/scources
2 participants