fix: download recent news

This commit is contained in:
2026-09-17 13:47:10 +03:00
parent ad64fdf4c5
commit b7183805c2
2 changed files with 8 additions and 5 deletions
@@ -22,9 +22,12 @@ interface NewsDao {
@Query("SELECT * FROM newsDB ORDER BY `publishedAt` DESC") @Query("SELECT * FROM newsDB ORDER BY `publishedAt` DESC")
fun paging(): PagingSource<Int, NewsDB> fun paging(): PagingSource<Int, NewsDB>
@Query("DELETE FROM newsDB")
suspend fun clear()
@Insert(onConflict = OnConflictStrategy.REPLACE) @Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertAll(news: List<NewsDB>) suspend fun insertAll(news: List<NewsDB>)
@Delete @Delete
suspend fun delete(unit: NewsDB) suspend fun delete(unit: NewsDB)
} }
@@ -64,9 +64,9 @@ class NewsRemoteMediator(
} }
db.withTransaction { db.withTransaction {
// if (loadType == LoadType.REFRESH) { if (loadType == LoadType.REFRESH) {
// db.newsDao().clear() db.newsDao().clear()
// } }
db.newsDao().insertAll( db.newsDao().insertAll(
news.map { it.toEntity() } news.map { it.toEntity() }
@@ -86,4 +86,4 @@ class NewsRemoteMediator(
MediatorResult.Error(e) MediatorResult.Error(e)
} }
} }
} }