fix download cache performance issue (#537)

* fix download cache performance issue

* adjust based of arkons suggestion

* launch the create in a scope to cut the faster loading time a little more
This commit is contained in:
Carlos 2020-07-25 21:28:28 -04:00 committed by GitHub
parent 1e9b9dabe3
commit 718165a58e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 23 deletions

View File

@ -75,11 +75,9 @@ class DownloadCache(
checkRenew() checkRenew()
val files = mangaFiles[manga.id]?.toSet() ?: return false val files = mangaFiles[manga.id]?.toHashSet() ?: return false
return files.any { file -> return provider.getValidChapterDirNames(chapter).any {
provider.getValidChapterDirNames(chapter).any { it in files
it.toLowerCase() == file.toLowerCase()
}
} }
} }

View File

@ -82,26 +82,33 @@ class MangaDetailsPresenter(
var headerItem = MangaHeaderItem(manga, controller.fromCatalogue) var headerItem = MangaHeaderItem(manga, controller.fromCatalogue)
fun onCreate() { fun onCreate() {
scope.launch {
withContext(Dispatchers.IO) {
isLockedFromSearch = SecureActivityDelegate.shouldBeLocked() isLockedFromSearch = SecureActivityDelegate.shouldBeLocked()
headerItem.isLocked = isLockedFromSearch headerItem.isLocked = isLockedFromSearch
downloadManager.addListener(this) downloadManager.addListener(this@MangaDetailsPresenter)
LibraryUpdateService.setListener(this) LibraryUpdateService.setListener(this@MangaDetailsPresenter)
tracks = db.getTracks(manga).executeAsBlocking() tracks = db.getTracks(manga).executeAsBlocking()
if (manga.source == LocalSource.ID) { if (manga.source == LocalSource.ID) {
refreshAll() refreshAll()
} else if (!manga.initialized) { } else if (!manga.initialized) {
isLoading = true isLoading = true
withContext(Dispatchers.Main) {
controller.setRefresh(true) controller.setRefresh(true)
controller.updateHeader() controller.updateHeader()
}
refreshAll() refreshAll()
} else { } else {
updateChapters() updateChapters()
controller.updateChapters(this.chapters) withContext(Dispatchers.Main) {
controller.updateChapters(this@MangaDetailsPresenter.chapters)
}
} }
setTrackItems() setTrackItems()
refreshTracking(false) refreshTracking(false)
} }
}
}
fun onDestroy() { fun onDestroy() {
downloadManager.removeListener(this) downloadManager.removeListener(this)