fix: 主页模块加载进搜索书籍数据库
Auto Release / prepare (push) Canceled after 0s
Auto Release / build (app, release) (push) Canceled after 0s
Auto Release / create_release (push) Canceled after 0s
CodeQL / Analyze (java-kotlin) (java-kotlin) (push) Canceled after 0s

This commit is contained in:
HapeLee
2026-07-02 23:33:52 +08:00
parent 0c15737b7b
commit bf73f84b71
3 changed files with 11 additions and 1 deletions
@@ -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(