From ee7ca26055959c0e0043fc6dd9c789d722b9d1fb Mon Sep 17 00:00:00 2001 From: Gino Miceli Date: Wed, 27 Nov 2024 15:28:31 -0500 Subject: [PATCH] Small refactor and TODO --- .../ground/persistence/sync/MediaUploadWorker.kt | 3 +-- .../ground/repository/MutationRepository.kt | 15 ++++++++++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/ground/src/main/java/com/google/android/ground/persistence/sync/MediaUploadWorker.kt b/ground/src/main/java/com/google/android/ground/persistence/sync/MediaUploadWorker.kt index c793b2fc5b..1c47b60eb5 100644 --- a/ground/src/main/java/com/google/android/ground/persistence/sync/MediaUploadWorker.kt +++ b/ground/src/main/java/com/google/android/ground/persistence/sync/MediaUploadWorker.kt @@ -56,8 +56,7 @@ constructor( override suspend fun doWork(): Result = withContext(Dispatchers.IO) { - val mutations = - mutationRepository.getIncompleteMediaUploads().mapNotNull { it.submissionMutation } + val mutations = mutationRepository.getIncompleteMediaUploads() Timber.d("Uploading photos for ${mutations.size} submission mutations") val results = mutations.map { uploadAllMedia(it) } if (results.all { it }) success() else retry() diff --git a/ground/src/main/java/com/google/android/ground/repository/MutationRepository.kt b/ground/src/main/java/com/google/android/ground/repository/MutationRepository.kt index 8f520cd862..533d0733fc 100644 --- a/ground/src/main/java/com/google/android/ground/repository/MutationRepository.kt +++ b/ground/src/main/java/com/google/android/ground/repository/MutationRepository.kt @@ -78,11 +78,16 @@ constructor( * Return the set of photo/media upload queue entries not yet marked as completed, sorted in * chronological order (FIFO). */ - suspend fun getIncompleteMediaUploads(): List = - getUploadQueueFlow().first().filter { - setOf(MEDIA_UPLOAD_PENDING, MEDIA_UPLOAD_IN_PROGRESS, MEDIA_UPLOAD_AWAITING_RETRY) - .contains(it.uploadStatus) - } + suspend fun getIncompleteMediaUploads(): List = + getUploadQueueFlow() + .first() + .filter { + setOf(MEDIA_UPLOAD_PENDING, MEDIA_UPLOAD_IN_PROGRESS, MEDIA_UPLOAD_AWAITING_RETRY) + .contains(it.uploadStatus) + } + // TODO(https://github.com/google/ground-android/issues/2120): + // Return [MediaMutations] instead once introduced. + .mapNotNull { it.submissionMutation } /** * Returns a [Flow] which emits the upload queue once and on each change, sorted in chronological