DownloadWorker: Update file and sharedLib list atomically

Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
Aayush Gupta
2024-02-21 17:54:06 +05:30
parent 13a08857b2
commit 11ac8092e2
2 changed files with 10 additions and 2 deletions

View File

@@ -5,6 +5,7 @@ import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Update
import com.aurora.gplayapi.data.models.File
import com.aurora.store.data.model.DownloadStatus
import kotlinx.coroutines.flow.Flow
@@ -20,6 +21,12 @@ interface DownloadDao {
@Query("UPDATE download SET downloadStatus=:downloadStatus WHERE packageName=:packageName")
suspend fun updateStatus(packageName: String, downloadStatus: DownloadStatus)
@Query("UPDATE download SET fileList=:fileList WHERE packageName=:packageName")
suspend fun updateFiles(packageName: String, fileList: List<File>)
@Query("UPDATE download SET sharedLibs=:sharedLibs WHERE packageName=:packageName")
suspend fun updateSharedLibs(packageName: String, sharedLibs: List<SharedLib>)
@Query(
"""
UPDATE download

View File

@@ -131,8 +131,9 @@ class DownloadWorker @AssistedInject constructor(
download.totalFiles = requestList.size
totalBytes = requestList.sumOf { it.size }
// Update database with all latest changes
downloadDao.update(download)
// Update database with all latest purchases
downloadDao.updateFiles(download.packageName, download.fileList)
downloadDao.updateSharedLibs(download.packageName, download.sharedLibs)
// Download and verify all files exists
requestList.forEach { request ->