Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete Drafts orphans after sending the Sentry about them #1927

Merged
merged 2 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ class ThreadController @Inject constructor(

/**
* Initialize and retrieve the search Threads obtained from the API.
* - Format the remote threads to make them compatible with the existing logic.
* - Preserve old message data if it already exists locally.
* - Format the remote Threads to make them compatible with the existing logic.
* - Preserve old Messages data if it already exists locally.
* - Handle duplicates using the existing logic.
* @param remoteThreads The list of API Threads that need to be processed.
* @param filterFolder The selected Folder on which we filter the Search.
Expand Down
8 changes: 3 additions & 5 deletions app/src/main/java/com/infomaniak/mail/utils/SentryDebug.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package com.infomaniak.mail.utils
import android.os.Bundle
import androidx.navigation.NavController
import com.infomaniak.mail.BuildConfig
import com.infomaniak.mail.data.cache.mailboxContent.DraftController
import com.infomaniak.mail.data.cache.mailboxContent.MessageController
import com.infomaniak.mail.data.cache.mailboxContent.ThreadController
import com.infomaniak.mail.data.models.Folder
Expand Down Expand Up @@ -242,13 +241,12 @@ object SentryDebug {
return orphanThreads
}

fun sendOrphanDrafts(realm: TypedRealm) {
val orphanDrafts = DraftController.getOrphanDrafts(realm)
if (orphanDrafts.isNotEmpty()) {
fun sendOrphanDrafts(orphans: List<Draft>) {
if (orphans.isNotEmpty()) {
Sentry.withScope { scope ->
scope.setExtra(
"orphanDrafts",
orphanDrafts.joinToString {
orphans.joinToString {
if (it.messageUid == null) {
"${Draft::localUuid.name}: [${it.localUuid}]"
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,11 @@ class DraftsActionsWorker @AssistedInject constructor(

mailboxContentRealm.executeRealmCallbacks(realmActionsOnDraft)

SentryDebug.sendOrphanDrafts(mailboxContentRealm)
mailboxContentRealm.writeBlocking {
val orphans = DraftController.getOrphanDrafts(realm = this)
SentryDebug.sendOrphanDrafts(orphans)
delete(orphans)
}

showDraftErrorNotification(isTrackedDraftSuccess, trackedDraftErrorMessageResId, trackedDraftAction)

Expand Down
Loading