Fix any potentially stuck thumbnail uploads.

This commit is contained in:
Greyson Parrelli
2025-12-08 11:17:55 -05:00
committed by Michelle Tang
parent 293dcb93d6
commit 6d32e534dc
2 changed files with 28 additions and 0 deletions

View File

@@ -106,6 +106,8 @@ import org.thoughtcrime.securesms.groups.GroupId
import org.thoughtcrime.securesms.jobmanager.Job
import org.thoughtcrime.securesms.jobmanager.impl.DataRestoreConstraint
import org.thoughtcrime.securesms.jobs.ArchiveAttachmentBackfillJob
import org.thoughtcrime.securesms.jobs.ArchiveThumbnailBackfillJob
import org.thoughtcrime.securesms.jobs.ArchiveThumbnailUploadJob
import org.thoughtcrime.securesms.jobs.AvatarGroupsV2DownloadJob
import org.thoughtcrime.securesms.jobs.BackupDeleteJob
import org.thoughtcrime.securesms.jobs.BackupMessagesJob
@@ -594,6 +596,7 @@ object BackupRepository {
}
if (SignalStore.backup.archiveUploadState?.backupPhase == ArchiveUploadProgressState.BackupPhase.Message && AppDependencies.jobManager.find { it.factoryKey == BackupMessagesJob.KEY }.isEmpty()) {
Log.w(TAG, "Found a situation where message backup was in progress, but there's no active BackupMessageJob! Re-enqueueing.")
SignalStore.backup.archiveUploadState = null
BackupMessagesJob.enqueue()
return
@@ -605,11 +608,18 @@ object BackupRepository {
if (!AppDependencies.jobManager.areQueuesEmpty(UploadAttachmentToArchiveJob.QUEUES)) {
if (SignalStore.backup.archiveUploadState?.state == ArchiveUploadProgressState.State.None) {
Log.w(TAG, "Found a situation where attachment uploads are in progress, but the progress state was None! Fixing.")
ArchiveUploadProgress.onAttachmentSectionStarted(SignalDatabase.attachments.getPendingArchiveUploadBytes())
}
return
}
if (AppDependencies.jobManager.areQueuesEmpty(ArchiveThumbnailUploadJob.QUEUES) && SignalDatabase.attachments.areAnyThumbnailsPendingUpload()) {
Log.w(TAG, "Found a situation where there's no thumbnail jobs in progress, but thumbnails are in the pending upload state! Clearing the pending state and re-enqueueing.")
SignalDatabase.attachments.clearArchiveThumbnailTransferStateForInProgressItems()
AppDependencies.jobManager.add(ArchiveThumbnailBackfillJob())
}
val pendingBytes = SignalDatabase.attachments.getPendingArchiveUploadBytes()
if (pendingBytes == 0L) {
return

View File

@@ -1105,6 +1105,17 @@ class AttachmentTable(
.run()
}
/**
* Resets the [ARCHIVE_THUMBNAIL_TRANSFER_STATE] of any attachments that are currently in-progress of uploading.
*/
fun clearArchiveThumbnailTransferStateForInProgressItems(): Int {
return writableDatabase
.update(TABLE_NAME)
.values(ARCHIVE_THUMBNAIL_TRANSFER_STATE to ArchiveTransferState.NONE.value)
.where("$ARCHIVE_THUMBNAIL_TRANSFER_STATE = ?", ArchiveTransferState.UPLOAD_IN_PROGRESS.value)
.run()
}
/**
* Marks eligible attachments as offloaded based on their received at timestamp, their last restore time,
* presence of thumbnail if media, and the full file being available in the archive.
@@ -1177,6 +1188,13 @@ class AttachmentTable(
.readToSingleLong()
}
fun areAnyThumbnailsPendingUpload(): Boolean {
return readableDatabase
.exists(TABLE_NAME)
.where("$ARCHIVE_THUMBNAIL_TRANSFER_STATE = ?", ArchiveTransferState.UPLOAD_IN_PROGRESS.value)
.run()
}
/**
* Clears out the incrementalMac for the specified [attachmentId], as well as any other attachments that share the same ([remoteKey], [plaintextHash]) pair (if present).
*/