Fix fetching related mangas from extensions was not concurrently

This commit is contained in:
Cuong M. Tran 2024-05-20 12:38:25 +07:00
parent 914a7d2aa9
commit ac86a9a2d9
No known key found for this signature in database
GPG key ID: 733AA7624B9315C2
2 changed files with 37 additions and 33 deletions

View file

@ -1111,7 +1111,6 @@ class MangaScreenModel(
val state = successState ?: return val state = successState ?: return
val relatedMangasEnabled = Injekt.get<SourcePreferences>().relatedMangas().get() val relatedMangasEnabled = Injekt.get<SourcePreferences>().relatedMangas().get()
try { try {
withIOContext {
if (state.source !is StubSource) { if (state.source !is StubSource) {
if (relatedMangasEnabled) { if (relatedMangasEnabled) {
state.source.getRelatedMangaList(state.manga.toSManga()) { pair, _ -> state.source.getRelatedMangaList(state.manga.toSManga()) { pair, _ ->
@ -1133,7 +1132,6 @@ class MangaScreenModel(
} }
} }
} }
}
} catch (e: Throwable) { } catch (e: Throwable) {
logcat(LogPriority.ERROR, e) logcat(LogPriority.ERROR, e)
val message = with(context) { e.formattedMessage } val message = with(context) { e.formattedMessage }

View file

@ -98,21 +98,27 @@ interface CatalogueSource : Source {
pushResults: suspend (relatedManga: Pair<String, List<SManga>>, completed: Boolean) -> Unit, pushResults: suspend (relatedManga: Pair<String, List<SManga>>, completed: Boolean) -> Unit,
) { ) {
if (!disableRelatedMangas) { if (!disableRelatedMangas) {
if (supportsRelatedMangas) {
coroutineScope { coroutineScope {
launch { if (supportsRelatedMangas) launch { getRelatedMangaListByExtension(manga, pushResults) }
runCatching { fetchRelatedMangaList(manga) } if (!disableRelatedMangasBySearch) launch { getRelatedMangaListBySearch(manga, pushResults) }
.onSuccess { if (it.isNotEmpty()) pushResults(Pair("", it), false) }
.onFailure {
logcat(LogPriority.ERROR, it) { "## fetchRelatedMangaList: $it" }
}
} }
} }
} }
if (!disableRelatedMangasBySearch) { /**
getRelatedMangaListBySearch(manga, pushResults) * Get related mangas provided by extension
} *
* @return a list of <keyword, related mangas>
* @since komikku/extensions-lib 1.6
*/
suspend fun getRelatedMangaListByExtension(
manga: SManga,
pushResults: suspend (relatedManga: Pair<String, List<SManga>>, completed: Boolean) -> Unit,
) {
runCatching { fetchRelatedMangaList(manga) }
.onSuccess { if (it.isNotEmpty()) pushResults(Pair("", it), false) }
.onFailure { e ->
logcat(LogPriority.ERROR, e) { "## getRelatedMangaListByExtension: $e" }
} }
} }
@ -152,12 +158,12 @@ interface CatalogueSource : Source {
} }
/** /**
* Fetch related mangas by searching for each keywords from manga's title. * Get related mangas by searching for each keywords from manga's title.
* *
* @return a list of <keyword, related mangas> * @return a list of <keyword, related mangas>
* @since komikku/extensions-lib 1.6 * @since komikku/extensions-lib 1.6
*/ */
private suspend fun getRelatedMangaListBySearch( suspend fun getRelatedMangaListBySearch(
manga: SManga, manga: SManga,
pushResults: suspend (relatedManga: Pair<String, List<SManga>>, completed: Boolean) -> Unit, pushResults: suspend (relatedManga: Pair<String, List<SManga>>, completed: Boolean) -> Unit,
) { ) {