From 11f640cfee427b8912cdc43fc3efc61e0f774aa7 Mon Sep 17 00:00:00 2001 From: AntsyLich <59261191+AntsyLich@users.noreply.github.com> Date: Thu, 11 Aug 2022 19:06:46 +0600 Subject: [PATCH] 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> --- .../interactor/SyncChaptersWithSource.kt | 17 +++++++++++++---- .../data/library/LibraryUpdateService.kt | 6 +++--- .../kanade/tachiyomi/ui/manga/MangaPresenter.kt | 2 +- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/eu/kanade/domain/chapter/interactor/SyncChaptersWithSource.kt b/app/src/main/java/eu/kanade/domain/chapter/interactor/SyncChaptersWithSource.kt index 71772a85e..d77cc597d 100644 --- a/app/src/main/java/eu/kanade/domain/chapter/interactor/SyncChaptersWithSource.kt +++ b/app/src/main/java/eu/kanade/domain/chapter/interactor/SyncChaptersWithSource.kt @@ -28,11 +28,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, manga: Manga, source: Source, - ): Pair, List> { + ): List { if (rawSourceChapters.isEmpty() && source.id != LocalSource.ID) { throw NoChaptersException() } @@ -114,7 +122,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() @@ -174,7 +182,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 } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt index 802bb77a8..4966fe243 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt @@ -350,7 +350,7 @@ class LibraryUpdateService( else -> { // Convert to the manga that contains new chapters mangaWithNotif.toDomainManga()?.let { domainManga -> - val (newChapters, _) = updateManga(domainManga) + val newChapters = updateManga(domainManga) val newDbChapters = newChapters.map { it.toDbChapter() } if (newChapters.isNotEmpty()) { @@ -428,7 +428,7 @@ class LibraryUpdateService( * @param manga the manga to update. * @return a pair of the inserted and removed chapters. */ - private suspend fun updateManga(manga: DomainManga): Pair, List> { + private suspend fun updateManga(manga: DomainManga): List { val source = sourceManager.getOrStub(manga.source) val mangaInfo: MangaInfo = manga.toMangaInfo() @@ -444,7 +444,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 diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt index 2119a0c8c..6ed4eed0d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt @@ -521,7 +521,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,