mirror of
https://github.com/mihonapp/mihon.git
synced 2025-05-04 18:41:12 +00:00
performance improvements
This commit is contained in:
parent
061e6a4c17
commit
04091f59e4
1 changed files with 13 additions and 14 deletions
|
@ -136,18 +136,19 @@ actual class LocalSource(
|
||||||
if (page != loadedPages + 1 || page == currentlyLoadingPage) return
|
if (page != loadedPages + 1 || page == currentlyLoadingPage) return
|
||||||
currentlyLoadingPage = loadedPages + 1
|
currentlyLoadingPage = loadedPages + 1
|
||||||
|
|
||||||
val localMangaList = runBlocking { getMangaList() }
|
val mangaDirPage = mangaDirChunks[page - 1]
|
||||||
val mangaPage = mangaDirChunks[page - 1].map { mangaDir ->
|
val dbManga = runBlocking { getDbManga(mangaDirPage) }
|
||||||
|
val mangaPage = mangaDirPage.map { mangaDir ->
|
||||||
SManga.create().apply manga@{
|
SManga.create().apply manga@{
|
||||||
url = mangaDir.name.toString()
|
url = mangaDir.name.toString()
|
||||||
dirLastModifiedAt = mangaDir.lastModified()
|
dirLastModifiedAt = mangaDir.lastModified()
|
||||||
|
|
||||||
mangaDir.name?.let { title = localMangaList[url]?.title ?: it }
|
mangaDir.name?.let { title = dbManga[url]?.title ?: it }
|
||||||
author = localMangaList[url]?.author
|
author = dbManga[url]?.author
|
||||||
artist = localMangaList[url]?.artist
|
artist = dbManga[url]?.artist
|
||||||
description = localMangaList[url]?.description
|
description = dbManga[url]?.description
|
||||||
genre = localMangaList[url]?.genre?.joinToString(", ") { it.trim() }
|
genre = dbManga[url]?.genre?.joinToString(", ") { it.trim() }
|
||||||
status = localMangaList[url]?.status?.toInt() ?: ComicInfoPublishingStatus.toSMangaValue("Unknown")
|
status = dbManga[url]?.status?.toInt() ?: ComicInfoPublishingStatus.toSMangaValue("Unknown")
|
||||||
|
|
||||||
// Try to find the cover
|
// Try to find the cover
|
||||||
coverManager.find(mangaDir.name.orEmpty())?.let {
|
coverManager.find(mangaDir.name.orEmpty())?.let {
|
||||||
|
@ -161,7 +162,7 @@ actual class LocalSource(
|
||||||
val chapter = chapters.last()
|
val chapter = chapters.last()
|
||||||
|
|
||||||
// only read metadata from disk if it the mangaDir has been modified
|
// only read metadata from disk if it the mangaDir has been modified
|
||||||
if (dirLastModifiedAt != localMangaList[url]?.dirLastModifiedAt) {
|
if (dirLastModifiedAt != dbManga[url]?.dirLastModifiedAt) {
|
||||||
when (val format = getFormat(chapter)) {
|
when (val format = getFormat(chapter)) {
|
||||||
is Format.Directory -> getMangaDetails(this@manga)
|
is Format.Directory -> getMangaDetails(this@manga)
|
||||||
is Format.Zip -> getMangaDetails(this@manga)
|
is Format.Zip -> getMangaDetails(this@manga)
|
||||||
|
@ -483,11 +484,9 @@ actual class LocalSource(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun getMangaList(): Map<String?, Manga?> {
|
private suspend fun getDbManga(mangaDirs: List<UniFile>): Map<String?, Manga?> {
|
||||||
return fileSystem.getFilesInBaseDirectory().toList()
|
return mangaDirs.map { mangaDir ->
|
||||||
.filter { it.isDirectory && it.name?.startsWith('.') == false }
|
mangaDir.name?.let { mangaRepository.getMangaByUrlAndSourceId(it, ID) }
|
||||||
.map { file ->
|
|
||||||
file.name?.let { mangaRepository.getMangaByUrlAndSourceId(it, ID) }
|
|
||||||
}
|
}
|
||||||
.associateBy { it?.url }
|
.associateBy { it?.url }
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue