diff --git a/app/shared/app-data/src/commonMain/kotlin/data/repository/subject/SubjectSearchRepository.kt b/app/shared/app-data/src/commonMain/kotlin/data/repository/subject/SubjectSearchRepository.kt index d8c1308cdb..68a8d6c2d3 100644 --- a/app/shared/app-data/src/commonMain/kotlin/data/repository/subject/SubjectSearchRepository.kt +++ b/app/shared/app-data/src/commonMain/kotlin/data/repository/subject/SubjectSearchRepository.kt @@ -9,6 +9,7 @@ package me.him188.ani.app.data.repository.subject +import androidx.collection.MutableIntList import androidx.paging.Pager import androidx.paging.PagingConfig import androidx.paging.PagingData @@ -21,7 +22,6 @@ import kotlinx.coroutines.flow.flowOn import kotlinx.coroutines.withContext import me.him188.ani.app.data.models.schedule.AnimeSeasonId import me.him188.ani.app.data.models.schedule.yearMonths -import me.him188.ani.app.data.network.AniSubjectSearchService import me.him188.ani.app.data.network.BangumiSearchFilters import me.him188.ani.app.data.network.BangumiSubjectSearchService import me.him188.ani.app.data.network.BatchSubjectDetails @@ -41,7 +41,6 @@ import kotlin.coroutines.cancellation.CancellationException class SubjectSearchRepository( private val bangumiSubjectSearchService: BangumiSubjectSearchService, - private val aniSubjectSearchService: AniSubjectSearchService, private val subjectCollectionRepository: SubjectCollectionRepository, private val subjectService: SubjectService, defaultDispatcher: CoroutineContext = Dispatchers.Default, @@ -79,7 +78,7 @@ class SubjectSearchRepository( val offset = params.key ?: return@withContext LoadResult.Error(IllegalArgumentException("Key is null")) return@withContext try { - val res = /*bangumiSubjectSearchService.searchSubjectIds*/aniSubjectSearchService.searchSubjects( + val res = bangumiSubjectSearchService.searchSubjectIds( searchQuery.keywords, useNewApi = useNewApi(), offset = offset, @@ -88,20 +87,23 @@ class SubjectSearchRepository( sort = searchQuery.sort.toBangumiSort(), ) - val filtered = if (ignoreDoneAndDropped()) { + val filteredIds = if (ignoreDoneAndDropped()) { val excludedIds = subjectCollectionRepository.getSubjectIdsByCollectionType( types = listOf(UnifiedCollectionType.DONE, UnifiedCollectionType.DROPPED), ).first() - buildList { - res.forEach { if (it.subjectInfo.subjectId !in excludedIds) add(it) } + MutableIntList().apply { + res.forEach { if (it !in excludedIds) add(it) } } } else { res } // 在分页源中直接过滤掉不符合条件的数据 #2380 - val subjectInfos = filterSubjectsBySort(filtered, searchQuery.sort) + val subjectInfos = filterSubjectsBySort( + subjectService.batchGetSubjectDetails(filteredIds), + searchQuery.sort, + ) return@withContext LoadResult.Page( subjectInfos, @@ -233,4 +235,3 @@ class SubjectSearchRepository( private fun SubjectType.toBangumiSubjectType(): BangumiSubjectType = when (this) { SubjectType.ANIME -> BangumiSubjectType.Anime } -