Cleaning up traks

This commit is contained in:
Koitharu
2020-06-20 11:35:42 +03:00
parent 1b4a65f476
commit 85f7477450
7 changed files with 22 additions and 9 deletions

View File

@@ -19,4 +19,7 @@ interface TrackLogsDao {
@Query("DELETE FROM track_logs WHERE manga_id = :mangaId")
suspend fun removeAll(mangaId: Long)
@Query("DELETE FROM track_logs WHERE manga_id NOT IN (SELECT manga_id FROM tracks)")
suspend fun cleanup()
}

View File

@@ -25,11 +25,13 @@ abstract class TracksDao {
@Query("DELETE FROM tracks WHERE manga_id = :mangaId")
abstract suspend fun delete(mangaId: Long)
@Query("DELETE FROM tracks WHERE manga_id NOT IN (SELECT manga_id FROM history UNION SELECT manga_id FROM favourites)")
abstract suspend fun cleanup()
@Transaction
open suspend fun upsert(entity: TrackEntity) {
if (update(entity) == 0) {
insert(entity)
}
}
}

View File

@@ -44,6 +44,13 @@ class TrackingRepository : KoinComponent {
}
}
suspend fun cleanup() {
db.withTransaction {
db.tracksDao.cleanup()
db.trackLogsDao.cleanup()
}
}
suspend fun storeTrackResult(
mangaId: Long,
knownChaptersCount: Int,

View File

@@ -118,6 +118,7 @@ class TrackWorker(context: Context, workerParams: WorkerParameters) :
}
success++
}
repo.cleanup()
if (success == 0) {
Result.retry()
} else {