Deduplicate entries when browsing (mihonapp/mihon#1957)

(cherry picked from commit f81da3dcce9afba883b6a3accdd3bf4ea21cfa81)
This commit is contained in:
AntsyLich 2025-04-03 01:48:54 +06:00 committed by Cuong-Tran
parent 9fe4573723
commit 50d31978b2
No known key found for this signature in database
GPG key ID: 733AA7624B9315C2
8 changed files with 22 additions and 14 deletions

View file

@ -20,6 +20,7 @@ The format is a modified version of [Keep a Changelog](https://keepachangelog.co
### Improved
- Significantly improve browsing speed (near instantaneous) ([@AntsyLich](https://github.com/AntsyLich)) ([#1946](https://github.com/mihonapp/mihon/pull/1946))
- Deduplicate entries when browsing ([@AntsyLich](https://github.com/AntsyLich)) ([#1957](https://github.com/mihonapp/mihon/pull/1957))
### Fixes
- Fix Bangumi search results including novels ([@MajorTanya](https://github.com/MajorTanya)) ([#1885](https://github.com/mihonapp/mihon/pull/1885))

View file

@ -301,7 +301,9 @@ open class FeedScreenModel(
val result = withIOContext {
itemUI.copy(
results = page.map { it.toDomainManga(itemUI.source!!.id) }
results = page
.map { it.toDomainManga(itemUI.source!!.id) }
.distinctBy { it.url }
.let { networkToLocalManga(it) }
// KMK -->
.filter { !hideInLibraryFeedItems.get() || !it.favorite },

View file

@ -212,6 +212,7 @@ open class SourceFeedScreenModel(
val titles = withIOContext {
page.map { it.toDomainManga(source.id) }
.distinctBy { it.url }
.let { networkToLocalManga(it) }
}

View file

@ -186,7 +186,9 @@ abstract class SearchScreenModel(
source.getSearchManga(1, query, source.getFilterList())
}
val titles = page.mangas.map { it.toDomainManga(source.id) }
val titles = page.mangas
.map { it.toDomainManga(source.id) }
.distinctBy { it.url }
.let { networkToLocalManga(it) }
if (isActive) {

View file

@ -1151,7 +1151,9 @@ class MangaScreenModel(
state.source.getRelatedMangaList(state.manga.toSManga(), { e -> exceptionHandler(e) }) { pair, _ ->
/* Push found related mangas into collection */
val relatedManga = RelatedManga.Success.fromPair(pair) { mangaList ->
mangaList.map { it.toDomainManga(state.source.id) }
mangaList
.map { it.toDomainManga(state.source.id) }
.distinctBy { it.url }
.let { networkToLocalManga(it) }
}
@ -2013,17 +2015,10 @@ sealed interface RelatedManga {
return map { relatedManga ->
if (relatedManga is Success) {
val stripedList = relatedManga.mangaList.mapNotNull {
if (!mangaIds.contains(it.id)) {
mangaIds.add(it.id)
it
} else {
null
}
}
Success(
relatedManga.keyword,
stripedList,
relatedManga.mangaList
.filter { mangaIds.add(it.id) },
)
} else {
relatedManga

View file

@ -86,6 +86,7 @@ open class RecommendsScreenModel(
// Otherwise, skip this step. The user will be prompted to choose a source via SmartSearch
page.mangas.map { it.toDomainManga(RECOMMENDS_SOURCE) }
}
.distinctBy { it.url }
if (isActive) {
updateItem(recSource, RecommendationItemResult.Success(titles))

View file

@ -17,7 +17,9 @@ abstract class EHentaiPagingSource(override val source: CatalogueSource) : BaseS
mangasPage as MetadataMangasPage
val metadata = mangasPage.mangasMetadata
val manga = mangasPage.mangas.map { it.toDomainManga(source.id) }
val manga = mangasPage.mangas
.map { it.toDomainManga(source.id) }
.filter { seenManga.add(it.url) }
.let { networkToLocalManga(it) }
// SY -->
.mapIndexed { index, manga -> manga to metadata.getOrNull(index) }

View file

@ -50,6 +50,8 @@ abstract class BaseSourcePagingSource(
protected val networkToLocalManga: NetworkToLocalManga = Injekt.get(),
) : SourcePagingSource() {
protected val seenManga = hashSetOf<String>()
abstract suspend fun requestNextPage(currentPage: Int): MangasPage
override suspend fun load(
@ -87,7 +89,9 @@ abstract class BaseSourcePagingSource(
}
// SY <--
val manga = mangasPage.mangas.map { it.toDomainManga(source!!.id) }
val manga = mangasPage.mangas
.map { it.toDomainManga(source!!.id) }
.filter { seenManga.add(it.url) }
.let { networkToLocalManga(it) }
// SY -->
.mapIndexed { index, manga -> manga to metadata.getOrNull(index) }