fix: 主页模块加载进搜索书籍数据库
This commit is contained in:
@@ -85,6 +85,12 @@ class ExploreRepositoryImpl(
|
|||||||
return WebBook.exploreBookSuspend(bookSource, url, page, key = key, isSearch = key != null)
|
return WebBook.exploreBookSuspend(bookSource, url, page, key = key, isSearch = key != null)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override suspend fun saveSearchBooks(books: List<SearchBook>) {
|
||||||
|
if (books.isNotEmpty()) {
|
||||||
|
appDb.searchBookDao.insert(books)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override suspend fun getSourceExploreKinds(sourceUrl: String): List<ExploreKind> = withContext(IO) {
|
override suspend fun getSourceExploreKinds(sourceUrl: String): List<ExploreKind> = withContext(IO) {
|
||||||
val source = appDb.bookSourceDao.getBookSource(sourceUrl)
|
val source = appDb.bookSourceDao.getBookSource(sourceUrl)
|
||||||
return@withContext source?.exploreKinds() ?: emptyList()
|
return@withContext source?.exploreKinds() ?: emptyList()
|
||||||
|
|||||||
@@ -11,4 +11,5 @@ interface ExploreBooksGateway {
|
|||||||
page: Int,
|
page: Int,
|
||||||
key: String? = null
|
key: String? = null
|
||||||
): List<SearchBook>
|
): List<SearchBook>
|
||||||
|
suspend fun saveSearchBooks(books: List<SearchBook>)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ class ExploreBooksUseCase(
|
|||||||
): ExploreResult = withContext(Dispatchers.IO) {
|
): ExploreResult = withContext(Dispatchers.IO) {
|
||||||
val request = resolveRequest(sourceUrl, moduleUrl, args, key)
|
val request = resolveRequest(sourceUrl, moduleUrl, args, key)
|
||||||
val books = gateway.exploreBooks(request.source, request.url, page, key = key)
|
val books = gateway.exploreBooks(request.source, request.url, page, key = key)
|
||||||
|
if (books.isNotEmpty()) gateway.saveSearchBooks(books)
|
||||||
ExploreResult(request.url, books)
|
ExploreResult(request.url, books)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,7 +48,9 @@ class ExploreBooksUseCase(
|
|||||||
if (next.isEmpty()) break
|
if (next.isEmpty()) break
|
||||||
books = (books + next)
|
books = (books + next)
|
||||||
}
|
}
|
||||||
books.take(MAX_RANKING_BOOKS)
|
val result = books.take(MAX_RANKING_BOOKS)
|
||||||
|
if (result.isNotEmpty()) gateway.saveSearchBooks(result)
|
||||||
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun resolveRequest(
|
private suspend fun resolveRequest(
|
||||||
|
|||||||
Reference in New Issue
Block a user