mirror of
https://github.com/gedoor/legado.git
synced 2024-08-30 09:23:26 +08:00
优化
This commit is contained in:
parent
8e7e82b213
commit
ae1558c029
@ -9,14 +9,17 @@ import io.legado.app.data.entities.rule.ContentRule
|
|||||||
import io.legado.app.exception.ContentEmptyException
|
import io.legado.app.exception.ContentEmptyException
|
||||||
import io.legado.app.exception.NoStackTraceException
|
import io.legado.app.exception.NoStackTraceException
|
||||||
import io.legado.app.help.book.BookHelp
|
import io.legado.app.help.book.BookHelp
|
||||||
|
import io.legado.app.help.config.AppConfig
|
||||||
import io.legado.app.model.Debug
|
import io.legado.app.model.Debug
|
||||||
import io.legado.app.model.analyzeRule.AnalyzeRule
|
import io.legado.app.model.analyzeRule.AnalyzeRule
|
||||||
import io.legado.app.model.analyzeRule.AnalyzeUrl
|
import io.legado.app.model.analyzeRule.AnalyzeUrl
|
||||||
import io.legado.app.utils.HtmlFormatter
|
import io.legado.app.utils.HtmlFormatter
|
||||||
import io.legado.app.utils.NetworkUtils
|
import io.legado.app.utils.NetworkUtils
|
||||||
|
import io.legado.app.utils.mapAsync
|
||||||
import kotlinx.coroutines.Dispatchers.IO
|
import kotlinx.coroutines.Dispatchers.IO
|
||||||
import kotlinx.coroutines.async
|
import kotlinx.coroutines.currentCoroutineContext
|
||||||
import kotlinx.coroutines.ensureActive
|
import kotlinx.coroutines.ensureActive
|
||||||
|
import kotlinx.coroutines.flow.flow
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import org.apache.commons.text.StringEscapeUtils
|
import org.apache.commons.text.StringEscapeUtils
|
||||||
import splitties.init.appCtx
|
import splitties.init.appCtx
|
||||||
@ -105,9 +108,11 @@ object BookContent {
|
|||||||
} else if (contentData.second.size > 1) {
|
} else if (contentData.second.size > 1) {
|
||||||
Debug.log(bookSource.bookSourceUrl, "◇并发解析正文,总页数:${contentData.second.size}")
|
Debug.log(bookSource.bookSourceUrl, "◇并发解析正文,总页数:${contentData.second.size}")
|
||||||
withContext(IO) {
|
withContext(IO) {
|
||||||
val asyncArray = Array(contentData.second.size) {
|
flow {
|
||||||
async(IO) {
|
for (urlStr in contentData.second) {
|
||||||
val urlStr = contentData.second[it]
|
emit(urlStr)
|
||||||
|
}
|
||||||
|
}.mapAsync(AppConfig.threadCount) { urlStr ->
|
||||||
val res = AnalyzeUrl(
|
val res = AnalyzeUrl(
|
||||||
mUrl = urlStr,
|
mUrl = urlStr,
|
||||||
source = bookSource,
|
source = bookSource,
|
||||||
@ -120,11 +125,9 @@ object BookContent {
|
|||||||
getNextPageUrl = false,
|
getNextPageUrl = false,
|
||||||
printLog = false
|
printLog = false
|
||||||
).first
|
).first
|
||||||
}
|
}.collect {
|
||||||
}
|
currentCoroutineContext().ensureActive()
|
||||||
asyncArray.forEach { coroutine ->
|
contentList.add(it)
|
||||||
coroutineContext.ensureActive()
|
|
||||||
contentList.add(coroutine.await())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user