mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
优化
This commit is contained in:
@@ -154,7 +154,8 @@ object BookHelp {
|
||||
bookSource: BookSource,
|
||||
book: Book,
|
||||
bookChapter: BookChapter,
|
||||
content: String
|
||||
content: String,
|
||||
concurrency: Int = AppConfig.threadCount
|
||||
) = coroutineScope {
|
||||
flow {
|
||||
val matcher = AppPattern.imgPattern.matcher(content)
|
||||
@@ -163,7 +164,7 @@ object BookHelp {
|
||||
val mSrc = NetworkUtils.getAbsoluteURL(bookChapter.url, src)
|
||||
emit(mSrc)
|
||||
}
|
||||
}.onEachParallel(AppConfig.threadCount) { mSrc ->
|
||||
}.onEachParallel(concurrency) { mSrc ->
|
||||
saveImage(bookSource, book, mSrc, bookChapter)
|
||||
}.collect()
|
||||
}
|
||||
|
||||
@@ -269,7 +269,7 @@ object CacheBook {
|
||||
if (BookHelp.hasContent(book, chapter)) {
|
||||
Coroutine.async(executeContext = context) {
|
||||
BookHelp.getContent(book, chapter)?.let {
|
||||
BookHelp.saveImages(bookSource, book, chapter, it)
|
||||
BookHelp.saveImages(bookSource, book, chapter, it, 1)
|
||||
}
|
||||
}.onSuccess {
|
||||
onSuccess(chapter)
|
||||
|
||||
@@ -27,6 +27,8 @@ import io.legado.app.utils.fastSum
|
||||
import io.legado.app.utils.splitNotBlank
|
||||
import kotlinx.coroutines.CancellationException
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.CoroutineStart
|
||||
import kotlinx.coroutines.Dispatchers.IO
|
||||
import kotlinx.coroutines.channels.Channel
|
||||
import kotlinx.coroutines.ensureActive
|
||||
import kotlinx.coroutines.launch
|
||||
@@ -83,7 +85,11 @@ class TextChapterLayout(
|
||||
var channel = Channel<TextPage>(Int.MAX_VALUE)
|
||||
|
||||
init {
|
||||
job = Coroutine.async(scope) {
|
||||
job = Coroutine.async(
|
||||
scope,
|
||||
start = CoroutineStart.LAZY,
|
||||
executeContext = IO
|
||||
) {
|
||||
launch {
|
||||
val bookSource = book.getBookSource() ?: return@launch
|
||||
BookHelp.saveImages(bookSource, book, bookChapter, bookContent.toString())
|
||||
@@ -95,6 +101,7 @@ class TextChapterLayout(
|
||||
}.onFinally {
|
||||
isCompleted = true
|
||||
}
|
||||
job.start()
|
||||
}
|
||||
|
||||
fun setProgressListener(l: LayoutProgressListener?) {
|
||||
|
||||
Reference in New Issue
Block a user