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 relatedMangasEnabled = Injekt.get<SourcePreferences>().relatedMangas().get()
try {
withIOContext {
if (state.source !is StubSource) {
if (relatedMangasEnabled) {
state.source.getRelatedMangaList(state.manga.toSManga()) { pair, _ ->
@ -1133,7 +1132,6 @@ class MangaScreenModel(
}
}
}
}
} catch (e: Throwable) {
logcat(LogPriority.ERROR, e)
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,
) {
if (!disableRelatedMangas) {
if (supportsRelatedMangas) {
coroutineScope {
launch {
runCatching { fetchRelatedMangaList(manga) }
.onSuccess { if (it.isNotEmpty()) pushResults(Pair("", it), false) }
.onFailure {
logcat(LogPriority.ERROR, it) { "## fetchRelatedMangaList: $it" }
}
if (supportsRelatedMangas) launch { getRelatedMangaListByExtension(manga, pushResults) }
if (!disableRelatedMangasBySearch) launch { getRelatedMangaListBySearch(manga, pushResults) }
}
}
}
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>
* @since komikku/extensions-lib 1.6
*/
private suspend fun getRelatedMangaListBySearch(
suspend fun getRelatedMangaListBySearch(
manga: SManga,
pushResults: suspend (relatedManga: Pair<String, List<SManga>>, completed: Boolean) -> Unit,
) {