优化rss加载逻辑 (#4286)

This commit is contained in:
老牛 2024-10-20 20:05:00 +08:00 committed by GitHub
parent 7523ffa318
commit 1c0a7bc7b4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 3 deletions

View File

@ -23,6 +23,9 @@ interface RssArticleDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insert(vararg rssArticle: RssArticle)
@Insert(onConflict = OnConflictStrategy.IGNORE)
fun append(vararg rssArticle: RssArticle)
@Query("delete from rssArticles where origin = :origin and sort = :sort and `order` < :order")
fun clearOld(origin: String, sort: String, order: Long)

View File

@ -80,14 +80,16 @@ class RssArticlesViewModel(application: Application) : BaseViewModel(application
return
}
val firstArticle = articles.first()
val dbArticle = appDb.rssArticleDao.get(firstArticle.origin, firstArticle.link)
if (dbArticle != null) {
val dbFirstArticle = appDb.rssArticleDao.get(firstArticle.origin, firstArticle.link)
val lastArticle = articles.last()
val dbLastArticle = appDb.rssArticleDao.get(lastArticle.origin, lastArticle.link)
if (dbFirstArticle != null && dbLastArticle != null) {
loadFinallyLiveData.postValue(false)
} else {
articles.forEach {
it.order = order--
}
appDb.rssArticleDao.insert(*articles.toTypedArray())
appDb.rssArticleDao.append(*articles.toTypedArray())
}
}