Change return value of SyncChaptersWithSource.await()
(#7715)
* Change return value of `SyncChaptersWithSource.await()` `updatedToAdd.subtract(reAdded).toList()` never worked as at this point `updatedToAdd` contained ids from db where `reAdded` had default one. Was the same case before the rewrite. Removed `toDelete` from return value as it was not being used anywhere * Add doc string * Use HashSet Co-authored-by: stevenyomi <95685115+stevenyomi@users.noreply.github.com> Co-authored-by: stevenyomi <95685115+stevenyomi@users.noreply.github.com> (cherry picked from commit 11f640cfee427b8912cdc43fc3efc61e0f774aa7) # Conflicts: # app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt # app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt
This commit is contained in:
parent
e9829129ae
commit
0b1afc1b94
@ -29,11 +29,19 @@ class SyncChaptersWithSource(
|
||||
private val getChapterByMangaId: GetChapterByMangaId = Injekt.get(),
|
||||
) {
|
||||
|
||||
/**
|
||||
* Method to synchronize db chapters with source ones
|
||||
*
|
||||
* @param rawSourceChapters the chapters from the source.
|
||||
* @param manga the manga the chapters belong to.
|
||||
* @param source the source the manga belongs to.
|
||||
* @return Newly added chapters
|
||||
*/
|
||||
suspend fun await(
|
||||
rawSourceChapters: List<SChapter>,
|
||||
manga: Manga,
|
||||
source: Source,
|
||||
): Pair<List<Chapter>, List<Chapter>> {
|
||||
): List<Chapter> {
|
||||
if (rawSourceChapters.isEmpty() && source.id != LocalSource.ID) {
|
||||
throw NoChaptersException()
|
||||
}
|
||||
@ -115,7 +123,7 @@ class SyncChaptersWithSource(
|
||||
|
||||
// Return if there's nothing to add, delete or change, avoiding unnecessary db transactions.
|
||||
if (toAdd.isEmpty() && toDelete.isEmpty() && toChange.isEmpty()) {
|
||||
return Pair(emptyList(), emptyList())
|
||||
return emptyList()
|
||||
}
|
||||
|
||||
val reAdded = mutableListOf<Chapter>()
|
||||
@ -191,7 +199,8 @@ class SyncChaptersWithSource(
|
||||
// Note that last_update actually represents last time the chapter list changed at all
|
||||
updateManga.awaitUpdateLastUpdate(manga.id)
|
||||
|
||||
@Suppress("ConvertArgumentToSet") // See tachiyomiorg/tachiyomi#6372.
|
||||
return Pair(updatedToAdd.subtract(reAdded).toList(), toDelete.subtract(reAdded).toList())
|
||||
val reAddedUrls = reAdded.map { it.url }.toHashSet()
|
||||
|
||||
return updatedToAdd.filterNot { it.url in reAddedUrls }
|
||||
}
|
||||
}
|
||||
|
@ -438,7 +438,7 @@ class LibraryUpdateService(
|
||||
else -> {
|
||||
// Convert to the manga that contains new chapters
|
||||
mangaWithNotif.toDomainManga()?.let { domainManga ->
|
||||
val (newChapters, _) = updateManga(domainManga, loggedServices)
|
||||
val newChapters = updateManga(domainManga, loggedServices)
|
||||
val newDbChapters = newChapters.map { it.toDbChapter() }
|
||||
|
||||
if (newChapters.isNotEmpty()) {
|
||||
@ -532,7 +532,7 @@ class LibraryUpdateService(
|
||||
* @param manga the manga to update.
|
||||
* @return a pair of the inserted and removed chapters.
|
||||
*/
|
||||
private suspend fun updateManga(manga: DomainManga, loggedServices: List<TrackService>): Pair<List<DomainChapter>, List<DomainChapter>> {
|
||||
private suspend fun updateManga(manga: DomainManga, loggedServices: List<TrackService>): List<DomainChapter> {
|
||||
val source = sourceManager.getOrStub(manga.source)
|
||||
|
||||
val mangaInfo: MangaInfo = manga.toMangaInfo()
|
||||
@ -567,7 +567,7 @@ class LibraryUpdateService(
|
||||
|
||||
// Get manga from database to account for if it was removed during the update
|
||||
val dbManga = getManga.await(manga.id)
|
||||
?: return Pair(emptyList(), emptyList())
|
||||
?: return emptyList()
|
||||
|
||||
// [dbmanga] was used so that manga data doesn't get overwritten
|
||||
// in case manga gets new chapter
|
||||
|
@ -163,7 +163,7 @@ class MergedSource : HttpSource() {
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun fetchChaptersAndSync(manga: Manga, downloadChapters: Boolean = true): Pair<List<Chapter>, List<Chapter>> {
|
||||
suspend fun fetchChaptersAndSync(manga: Manga, downloadChapters: Boolean = true): List<Chapter> {
|
||||
val syncChaptersWithSource = Injekt.get<SyncChaptersWithSource>()
|
||||
val mangaReferences = getMergedReferencesById.await(manga.id)
|
||||
if (mangaReferences.isEmpty()) {
|
||||
@ -180,7 +180,7 @@ class MergedSource : HttpSource() {
|
||||
.map { (_, values) ->
|
||||
async {
|
||||
semaphore.withPermit {
|
||||
values.map {
|
||||
values.flatMap {
|
||||
try {
|
||||
val (source, loadedManga, reference) =
|
||||
it.load(sourceManager, getManga, insertManga, updateManga)
|
||||
@ -192,17 +192,17 @@ class MergedSource : HttpSource() {
|
||||
if (ifDownloadNewChapters && reference.downloadChapters) {
|
||||
downloadManager.downloadChapters(
|
||||
loadedManga,
|
||||
results.first.map(Chapter::toDbChapter),
|
||||
results.map(Chapter::toDbChapter),
|
||||
)
|
||||
}
|
||||
results
|
||||
} else {
|
||||
null
|
||||
emptyList()
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
if (e is CancellationException) throw e
|
||||
exception = e
|
||||
null
|
||||
emptyList()
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -210,9 +210,6 @@ class MergedSource : HttpSource() {
|
||||
}
|
||||
.awaitAll()
|
||||
.flatten()
|
||||
.let { pairs ->
|
||||
pairs.flatMap { it?.first.orEmpty() } to pairs.flatMap { it?.second.orEmpty() }
|
||||
}
|
||||
}.also {
|
||||
exception?.let { throw it }
|
||||
}
|
||||
|
@ -967,7 +967,7 @@ class MangaPresenter(
|
||||
val chapters = successState.source.getChapterList(successState.manga.toMangaInfo())
|
||||
.map { it.toSChapter() }
|
||||
|
||||
val (newChapters, _) = syncChaptersWithSource.await(
|
||||
val newChapters = syncChaptersWithSource.await(
|
||||
chapters,
|
||||
successState.manga,
|
||||
successState.source,
|
||||
|
@ -209,7 +209,7 @@ class EHentaiUpdateWorker(private val context: Context, workerParams: WorkerPara
|
||||
val newChapters = source.getChapterList(manga.toMangaInfo())
|
||||
.map { it.toSChapter() }
|
||||
|
||||
val (new, _) = syncChaptersWithSource.await(newChapters, manga, source)
|
||||
val new = syncChaptersWithSource.await(newChapters, manga, source)
|
||||
return new to getChapterByMangaId.await(manga.id)
|
||||
} catch (t: Throwable) {
|
||||
if (t is EHentai.GalleryNotFoundException) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user