mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2025-01-09 20:49:25 +01:00
Fixed cache missing items sometimes
This commit is contained in:
parent
649211a1cb
commit
9a09338977
@ -44,10 +44,6 @@ class DownloadCache(
|
|||||||
*/
|
*/
|
||||||
private var lastRenew = 0L
|
private var lastRenew = 0L
|
||||||
|
|
||||||
/**
|
|
||||||
* The root directory for downloads.
|
|
||||||
*/
|
|
||||||
//private var rootDir = RootDirectory(getDirectoryFromPreference())
|
|
||||||
private var mangaFiles: MutableMap<Long, MutableSet<String>> = mutableMapOf()
|
private var mangaFiles: MutableMap<Long, MutableSet<String>> = mutableMapOf()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
@ -55,7 +51,6 @@ class DownloadCache(
|
|||||||
.skip(1)
|
.skip(1)
|
||||||
.subscribe {
|
.subscribe {
|
||||||
lastRenew = 0L // invalidate cache
|
lastRenew = 0L // invalidate cache
|
||||||
//rootDir = RootDirectory(getDirectoryFromPreference())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,14 +116,14 @@ class DownloadCache(
|
|||||||
.mapNotNullKeys { entry ->
|
.mapNotNullKeys { entry ->
|
||||||
onlineSources.find { provider.getSourceDirName(it) == entry.key }?.id
|
onlineSources.find { provider.getSourceDirName(it) == entry.key }?.id
|
||||||
}
|
}
|
||||||
//Timber.i("Sources: ${sourceDirs.map { it.value.dir.filePath }.joinToString(", ")}")
|
|
||||||
|
|
||||||
//rootDir.files = sourceDirs
|
|
||||||
|
|
||||||
val db:DatabaseHelper by injectLazy()
|
val db:DatabaseHelper by injectLazy()
|
||||||
val mangas = db.getMangas().executeAsBlocking()
|
val mangas = db.getMangas().executeAsBlocking().groupBy { it.source }
|
||||||
|
|
||||||
sourceDirs.forEach { sourceValue ->
|
sourceDirs.forEach { sourceValue ->
|
||||||
|
val sourceMangasRaw = mangas[sourceValue.key]?.toMutableSet() ?: return@forEach
|
||||||
|
val sourceMangas = arrayOf(sourceMangasRaw.filter { it.favorite }, sourceMangasRaw
|
||||||
|
.filterNot { it.favorite })
|
||||||
val sourceDir = sourceValue.value
|
val sourceDir = sourceValue.value
|
||||||
val mangaDirs = sourceDir.dir.listFiles()
|
val mangaDirs = sourceDir.dir.listFiles()
|
||||||
.orEmpty()
|
.orEmpty()
|
||||||
@ -136,25 +131,24 @@ class DownloadCache(
|
|||||||
val name = it.name ?: return@mapNotNull null
|
val name = it.name ?: return@mapNotNull null
|
||||||
name to MangaDirectory(it) }.toMap()
|
name to MangaDirectory(it) }.toMap()
|
||||||
|
|
||||||
// Timber.i("${sourceDir.dir.name}: ${mangaDirs.map {
|
|
||||||
// it.key + " :: " + it.value.dir.filePath }.joinToString(", ")}")
|
|
||||||
|
|
||||||
mangaDirs.values.forEach { mangaDir ->
|
mangaDirs.values.forEach { mangaDir ->
|
||||||
val chapterDirs = mangaDir.dir.listFiles()
|
val chapterDirs = mangaDir.dir.listFiles()
|
||||||
.orEmpty()
|
.orEmpty()
|
||||||
.mapNotNull { it.name }
|
.mapNotNull { it.name }
|
||||||
.toHashSet()
|
.toHashSet()
|
||||||
// Timber.i("${mangaDir.dir.name}: ${chapterDirs.joinToString(", ")}")
|
|
||||||
mangaDir.files = chapterDirs
|
mangaDir.files = chapterDirs
|
||||||
}
|
}
|
||||||
val trueMangaDirs = mangaDirs.mapNotNull { mangaDir ->
|
val trueMangaDirs = mangaDirs.mapNotNull { mangaDir ->
|
||||||
val manga = mangas.find { DiskUtil.buildValidFilename(it.originalTitle()) ==
|
val manga = sourceMangas.firstOrNull()?.find { DiskUtil.buildValidFilename(
|
||||||
mangaDir.key && it.source == sourceValue.key }
|
it.originalTitle()).toLowerCase() == mangaDir.key
|
||||||
|
.toLowerCase() && it.source == sourceValue.key } ?:
|
||||||
|
sourceMangas.lastOrNull()?.find { DiskUtil.buildValidFilename(
|
||||||
|
it.originalTitle()).toLowerCase() == mangaDir.key
|
||||||
|
.toLowerCase() && it.source == sourceValue.key }
|
||||||
val id = manga?.id ?: return@mapNotNull null
|
val id = manga?.id ?: return@mapNotNull null
|
||||||
id to mangaDir.value.files
|
id to mangaDir.value.files
|
||||||
}.toMap()
|
}.toMap()
|
||||||
|
|
||||||
//sourceDir.files = trueMangaDirs
|
|
||||||
mangaFiles.putAll(trueMangaDirs)
|
mangaFiles.putAll(trueMangaDirs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -379,17 +379,6 @@ class LibraryUpdateService(
|
|||||||
cancelProgressNotification()
|
cancelProgressNotification()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun cleanupDownloads() {
|
|
||||||
val mangaList = db.getMangas().executeAsBlocking()
|
|
||||||
var foldersCleared = 0
|
|
||||||
for (manga in mangaList) {
|
|
||||||
val chapterList = db.getChapters(manga).executeAsBlocking()
|
|
||||||
val source = sourceManager.getOrStub(manga.source)
|
|
||||||
foldersCleared += downloadManager.cleanupChapters(chapterList, manga, source)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
fun downloadChapters(manga: Manga, chapters: List<Chapter>) {
|
fun downloadChapters(manga: Manga, chapters: List<Chapter>) {
|
||||||
// we need to get the chapters from the db so we have chapter ids
|
// we need to get the chapters from the db so we have chapter ids
|
||||||
val mangaChapters = db.getChapters(manga).executeAsBlocking()
|
val mangaChapters = db.getChapters(manga).executeAsBlocking()
|
||||||
|
@ -97,7 +97,7 @@ class LibraryUpdateServiceTest {
|
|||||||
|
|
||||||
val intent = Intent()
|
val intent = Intent()
|
||||||
val target = LibraryUpdateService.Target.CHAPTERS
|
val target = LibraryUpdateService.Target.CHAPTERS
|
||||||
service.updateChapterList(service.getMangaToUpdate(intent, target)).subscribe()
|
service.updateDetails(favManga).subscribe()
|
||||||
|
|
||||||
// There are 3 network attempts and 2 insertions (1 request failed)
|
// There are 3 network attempts and 2 insertions (1 request failed)
|
||||||
assertThat(service.db.getChapters(favManga[0]).executeAsBlocking()).hasSize(2)
|
assertThat(service.db.getChapters(favManga[0]).executeAsBlocking()).hasSize(2)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user