优化小说更新

pull/341/head^2
gedoor 4 years ago
parent ef504403b0
commit c4303af574
  1. 32
      app/src/main/java/io/legado/app/ui/main/MainViewModel.kt

@ -48,29 +48,31 @@ class MainViewModel(application: Application) : BaseViewModel(application) {
} }
fun upToc(books: List<Book>) { fun upToc(books: List<Book>) {
books.filter { execute {
it.origin != BookType.local && it.canUpdate books.filter {
}.forEach { it.origin != BookType.local && it.canUpdate
bookMap[it.bookUrl] = it }.forEach {
} bookMap[it.bookUrl] = it
for (i in 0 until threadCount) { }
if (usePoolCount < threadCount) { for (i in 0 until threadCount) {
usePoolCount++ if (usePoolCount < threadCount) {
updateToc() usePoolCount++
updateToc()
}
} }
} }
} }
private fun updateToc() { private fun updateToc() {
execute { synchronized(this) {
bookMap.forEach { bookEntry -> bookMap.forEach { bookEntry ->
if (!updateList.contains(bookEntry.key)) { if (!updateList.contains(bookEntry.key)) {
val book = bookEntry.value val book = bookEntry.value
synchronized(this) {
updateList.add(book.bookUrl)
postEvent(EventBus.UP_BOOK, book.bookUrl)
}
App.db.bookSourceDao().getBookSource(book.origin)?.let { bookSource -> App.db.bookSourceDao().getBookSource(book.origin)?.let { bookSource ->
synchronized(this) {
updateList.add(book.bookUrl)
postEvent(EventBus.UP_BOOK, book.bookUrl)
}
WebBook(bookSource).getChapterList(book, context = upTocPool) WebBook(bookSource).getChapterList(book, context = upTocPool)
.timeout(300000) .timeout(300000)
.onSuccess(IO) { .onSuccess(IO) {
@ -91,6 +93,8 @@ class MainViewModel(application: Application) : BaseViewModel(application) {
} }
} ?: synchronized(this) { } ?: synchronized(this) {
bookMap.remove(bookEntry.key) bookMap.remove(bookEntry.key)
updateList.remove(book.bookUrl)
postEvent(EventBus.UP_BOOK, book.bookUrl)
upNext() upNext()
} }
return@forEach return@forEach

Loading…
Cancel
Save