Skip to content

Commit

Permalink
优化rss加载逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
niu-hb committed Oct 18, 2024
1 parent bb21d17 commit 7b445d9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
3 changes: 3 additions & 0 deletions app/src/main/java/io/legado/app/data/dao/RssArticleDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}

Expand Down

0 comments on commit 7b445d9

Please sign in to comment.