Massively improve findFile performance (#728)

* Massively improve findFile performance

* Update libs.versions.toml

---------

Co-authored-by: AntsyLich <59261191+AntsyLich@users.noreply.github.com>
(cherry picked from commit 7ec2108812fbe0483111dbe996e29e5a621b583a)
This commit is contained in:
Radon Rosborough 2024-05-04 09:40:41 -07:00 committed by Jobobby04
parent 712cd1493f
commit 089e6268e7
6 changed files with 11 additions and 11 deletions

View File

@ -475,7 +475,7 @@ class DownloadManager(
fun renameMangaDir(oldTitle: String, newTitle: String, source: Long) {
val sourceDir = provider.findSourceDir(sourceManager.getOrStub(source)) ?: return
val mangaDir = sourceDir.findFile(DiskUtil.buildValidFilename(oldTitle), true) ?: return
val mangaDir = sourceDir.findFile(DiskUtil.buildValidFilename(oldTitle)) ?: return
mangaDir.renameTo(DiskUtil.buildValidFilename(newTitle))
}
}

View File

@ -57,7 +57,7 @@ class DownloadProvider(
* @param source the source to query.
*/
fun findSourceDir(source: Source): UniFile? {
return downloadsDir?.findFile(getSourceDirName(source), true)
return downloadsDir?.findFile(getSourceDirName(source))
}
/**
@ -68,7 +68,7 @@ class DownloadProvider(
*/
fun findMangaDir(mangaTitle: String, source: Source): UniFile? {
val sourceDir = findSourceDir(source)
return sourceDir?.findFile(getMangaDirName(mangaTitle), true)
return sourceDir?.findFile(getMangaDirName(mangaTitle))
}
/**
@ -82,7 +82,7 @@ class DownloadProvider(
fun findChapterDir(chapterName: String, chapterScanlator: String?, mangaTitle: String, source: Source): UniFile? {
val mangaDir = findMangaDir(mangaTitle, source)
return getValidChapterDirNames(chapterName, chapterScanlator).asSequence()
.mapNotNull { mangaDir?.findFile(it, true) }
.mapNotNull { mangaDir?.findFile(it) }
.firstOrNull()
}
@ -97,7 +97,7 @@ class DownloadProvider(
val mangaDir = findMangaDir(/* SY --> */ manga.ogTitle /* SY <-- */, source) ?: return null to emptyList()
return mangaDir to chapters.mapNotNull { chapter ->
getValidChapterDirNames(chapter.name, chapter.scanlator).asSequence()
.mapNotNull { mangaDir.findFile(it, true) }
.mapNotNull { mangaDir.findFile(it) }
.firstOrNull()
}
}

View File

@ -709,7 +709,7 @@ class Downloader(
)
// Remove the old file
dir.findFile(COMIC_INFO_FILE, true)?.delete()
dir.findFile(COMIC_INFO_FILE)?.delete()
dir.createFile(COMIC_INFO_FILE)!!.openOutputStream().use {
val comicInfoString = xml.encodeToString(ComicInfo.serializer(), comicInfo)
it.write(comicInfoString.toByteArray())

View File

@ -32,7 +32,7 @@ quickjs-android = "app.cash.quickjs:quickjs-android:0.9.2"
jsoup = "org.jsoup:jsoup:1.17.2"
disklrucache = "com.jakewharton:disklrucache:2.0.2"
unifile = "com.github.tachiyomiorg:unifile:7c257e1c64"
unifile = "com.github.tachiyomiorg:unifile:e0def6b3dc"
common-compress = "org.apache.commons:commons-compress:1.26.1"
junrar = "com.github.junrar:junrar:7.5.5"
zip4j = "net.lingala.zip4j:zip4j:2.11.5"

View File

@ -368,8 +368,8 @@ actual class LocalSource(
try {
val (mangaDirName, chapterName) = chapter.url.split('/', limit = 2)
return fileSystem.getBaseDirectory()
?.findFile(mangaDirName, true)
?.findFile(chapterName, true)
?.findFile(mangaDirName)
?.findFile(chapterName)
?.let(Format.Companion::valueOf)
?: throw Exception(context.stringResource(MR.strings.chapter_not_found))
} catch (e: Format.UnknownFormatException) {

View File

@ -17,13 +17,13 @@ actual class LocalSourceFileSystem(
actual fun getMangaDirectory(name: String): UniFile? {
return getBaseDirectory()
?.findFile(name, true)
?.findFile(name)
?.takeIf { it.isDirectory }
}
actual fun getFilesInMangaDirectory(name: String): List<UniFile> {
return getBaseDirectory()
?.findFile(name, true)
?.findFile(name)
?.takeIf { it.isDirectory }
?.listFiles().orEmpty().toList()
}