mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
优化
This commit is contained in:
@@ -82,12 +82,13 @@ class SearchModel(private val scope: CoroutineScope, private val callBack: CallB
|
||||
source,
|
||||
searchKey,
|
||||
searchPage,
|
||||
context = searchPool
|
||||
context = searchPool,
|
||||
executeContext = searchPool
|
||||
).timeout(30000L)
|
||||
.onSuccess(searchPool) {
|
||||
.onSuccess {
|
||||
onSuccess(searchId, it)
|
||||
}
|
||||
.onFinally(searchPool) {
|
||||
.onFinally {
|
||||
onFinally(searchId)
|
||||
}
|
||||
tasks.add(task)
|
||||
|
||||
@@ -30,8 +30,9 @@ object WebBook {
|
||||
key: String,
|
||||
page: Int? = 1,
|
||||
context: CoroutineContext = Dispatchers.IO,
|
||||
executeContext: CoroutineContext = Dispatchers.Main,
|
||||
): Coroutine<ArrayList<SearchBook>> {
|
||||
return Coroutine.async(scope, context) {
|
||||
return Coroutine.async(scope, context, executeContext = executeContext) {
|
||||
searchBookAwait(bookSource, key, page)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,7 +192,7 @@ open class ChangeBookSourceViewModel(application: Application) : BaseViewModel(a
|
||||
searchIndex++
|
||||
}
|
||||
val source = bookSourceList[searchIndex]
|
||||
val task = Coroutine.async(scope = viewModelScope, context = searchPool!!) {
|
||||
val task = execute(context = searchPool!!, executeContext = searchPool!!) {
|
||||
val resultBooks = WebBook.searchBookAwait(source, name)
|
||||
resultBooks.forEach { searchBook ->
|
||||
if (searchBook.name != name) {
|
||||
@@ -336,8 +336,8 @@ open class ChangeBookSourceViewModel(application: Application) : BaseViewModel(a
|
||||
searchIndex++
|
||||
}
|
||||
val searchBook = searchBookList[searchIndex]
|
||||
val task = Coroutine.async(scope = viewModelScope, context = searchPool!!) {
|
||||
val source = appDb.bookSourceDao.getBookSource(searchBook.origin) ?: return@async
|
||||
val task = execute(context = searchPool!!, executeContext = searchPool!!) {
|
||||
val source = appDb.bookSourceDao.getBookSource(searchBook.origin) ?: return@execute
|
||||
loadBookInfo(source, searchBook.toBook())
|
||||
}.timeout(60000L)
|
||||
.onError {
|
||||
@@ -438,15 +438,13 @@ open class ChangeBookSourceViewModel(application: Application) : BaseViewModel(a
|
||||
|
||||
suspend fun getToc(book: Book): Result<Pair<List<BookChapter>, BookSource>> {
|
||||
return kotlin.runCatching {
|
||||
withContext(IO) {
|
||||
val source = appDb.bookSourceDao.getBookSource(book.origin)
|
||||
?: throw NoStackTraceException("书源不存在")
|
||||
if (book.tocUrl.isEmpty()) {
|
||||
WebBook.getBookInfoAwait(source, book)
|
||||
}
|
||||
val toc = WebBook.getChapterListAwait(source, book).getOrThrow()
|
||||
Pair(toc, source)
|
||||
val source = appDb.bookSourceDao.getBookSource(book.origin)
|
||||
?: throw NoStackTraceException("书源不存在")
|
||||
if (book.tocUrl.isEmpty()) {
|
||||
WebBook.getBookInfoAwait(source, book)
|
||||
}
|
||||
val toc = WebBook.getChapterListAwait(source, book).getOrThrow()
|
||||
Pair(toc, source)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user