Massively improve findFile performance (#728)

* Massively improve findFile performance

* Update libs.versions.toml

---------

Co-authored-by: AntsyLich <59261191+AntsyLich@users.noreply.github.com>
This commit is contained in:
Radon Rosborough 2024-05-04 09:40:41 -07:00 committed by GitHub
parent e55e5f6f64
commit 7ec2108812
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 9 additions and 9 deletions

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(manga.title, 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

@ -645,7 +645,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

@ -31,7 +31,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"

View File

@ -300,8 +300,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,7 +17,7 @@ actual class LocalSourceFileSystem(
actual fun getMangaDirectory(name: String): UniFile? {
return getBaseDirectory()
?.findFile(name, true)
?.findFile(name)
?.takeIf { it.isDirectory }
}