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