Fix some database-related crashes
This commit is contained in:
@@ -100,7 +100,11 @@ abstract class ChaptersPagesViewModel(
|
||||
}.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), false)
|
||||
|
||||
val bookmarks = mangaDetails.flatMapLatest {
|
||||
if (it != null) bookmarksRepository.observeBookmarks(it.toManga()) else flowOf(emptyList())
|
||||
if (it != null) {
|
||||
bookmarksRepository.observeBookmarks(it.toManga()).withErrorHandling()
|
||||
} else {
|
||||
flowOf(emptyList())
|
||||
}
|
||||
}.stateIn(viewModelScope + Dispatchers.Default, SharingStarted.Lazily, emptyList())
|
||||
|
||||
val chapters = combine(
|
||||
|
||||
@@ -27,17 +27,17 @@ abstract class TracksDao : MangaQueryBuilder.ConditionCallback {
|
||||
@Query("SELECT * FROM tracks WHERE manga_id = :mangaId")
|
||||
abstract suspend fun find(mangaId: Long): TrackEntity?
|
||||
|
||||
@Query("SELECT chapters_new FROM tracks WHERE manga_id = :mangaId")
|
||||
abstract suspend fun findNewChapters(mangaId: Long): Int?
|
||||
@Query("SELECT IFNULL(chapters_new,0) FROM tracks WHERE manga_id = :mangaId")
|
||||
abstract suspend fun findNewChapters(mangaId: Long): Int
|
||||
|
||||
@Query("SELECT COUNT(*) FROM tracks")
|
||||
abstract suspend fun getTracksCount(): Int
|
||||
|
||||
@Query("SELECT chapters_new FROM tracks")
|
||||
abstract fun observeNewChapters(): Flow<List<Int>>
|
||||
@Query("SELECT COUNT(*) FROM tracks WHERE chapters_new > 0")
|
||||
abstract fun observeUpdateMangaCount(): Flow<Int>
|
||||
|
||||
@Query("SELECT chapters_new FROM tracks WHERE manga_id = :mangaId")
|
||||
abstract fun observeNewChapters(mangaId: Long): Flow<Int?>
|
||||
@Query("SELECT IFNULL(chapters_new, 0) FROM tracks WHERE manga_id = :mangaId")
|
||||
abstract fun observeNewChapters(mangaId: Long): Flow<Int>
|
||||
|
||||
@Transaction
|
||||
@Query("SELECT * FROM tracks WHERE chapters_new > 0 ORDER BY last_chapter_date DESC")
|
||||
|
||||
@@ -5,7 +5,6 @@ import androidx.room.withTransaction
|
||||
import dagger.Reusable
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.onStart
|
||||
import org.koitharu.kotatsu.core.db.MangaDatabase
|
||||
import org.koitharu.kotatsu.core.db.entity.toManga
|
||||
@@ -39,16 +38,16 @@ class TrackingRepository @Inject constructor(
|
||||
private var isGcCalled = AtomicBoolean(false)
|
||||
|
||||
suspend fun getNewChaptersCount(mangaId: Long): Int {
|
||||
return db.getTracksDao().findNewChapters(mangaId) ?: 0
|
||||
return db.getTracksDao().findNewChapters(mangaId)
|
||||
}
|
||||
|
||||
fun observeNewChaptersCount(mangaId: Long): Flow<Int> {
|
||||
return db.getTracksDao().observeNewChapters(mangaId).map { it ?: 0 }
|
||||
return db.getTracksDao().observeNewChapters(mangaId)
|
||||
}
|
||||
|
||||
@Deprecated("")
|
||||
fun observeUpdatedMangaCount(): Flow<Int> {
|
||||
return db.getTracksDao().observeNewChapters().map { list -> list.count { it > 0 } }
|
||||
return db.getTracksDao().observeUpdateMangaCount()
|
||||
.onStart { gcIfNotCalled() }
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ class TrackerDebugViewModel @Inject constructor(
|
||||
|
||||
val content = db.getTracksDao().observeAll()
|
||||
.map { it.toUiList() }
|
||||
.withErrorHandling()
|
||||
.stateIn(viewModelScope + Dispatchers.Default, SharingStarted.Eagerly, emptyList())
|
||||
|
||||
private fun List<TrackWithManga>.toUiList(): List<TrackDebugItem> = map {
|
||||
|
||||
Reference in New Issue
Block a user