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

Wrong progress message when optimizing current preset #18006

Open
4 tasks done
user1823 opened this issue Feb 22, 2025 · 3 comments
Open
4 tasks done

Wrong progress message when optimizing current preset #18006

user1823 opened this issue Feb 22, 2025 · 3 comments

Comments

@user1823
Copy link
Contributor

user1823 commented Feb 22, 2025

Checked for duplicates?

  • This issue is not a duplicate

Does it also happen in the desktop version?

  • This bug does not occur in the latest version of Anki Desktop

What are the steps to reproduce this bug?

In the deck options page, click "Optimize current preset"

Expected behaviour

There should be no progress popup because the svelte page shows the progress.

However, in AnkiDroid 2.21 alphas, an "Updating cards" progress is shown, which is technically incorrect as the cards are not being updated at that stage.

Most likely cause:

@david-allison, FYI.

Debug info

AnkiDroid 2.21 alpha 13

(Optional) Anything else you want to share?

In the previous PR by David, there was some confusion about which progress message to use. So, let me clarify.
There are three buttons that a user can press. Let's discuss each one in turn.

  1. Optimize current preset: Don't show any progress dialog because the Svelte page shows a progress.
  2. Optimize all presets: This button performs two actions - Optimization and updating cards using the new parameters. Show optimizing presets 1/n... when on the optimizing step and then Updating cards 1/n when on the updating cards step.
  3. Save (top right) after changing the parameters or desired retention (manually or by optimize current preset button): Show the Updating cards 1/n popup.

Research

  • I have checked the manual and the FAQ and could not find a solution to my issue
  • (Optional) I have confirmed the issue is not resolved in the latest alpha release (instructions)
@david-allison
Copy link
Member

@david-allison
Copy link
Member

david-allison commented Feb 24, 2025

There should be no progress popup because the svelte page shows the progress.

On Anki 038d85b1 on my PC, I see progress in the WebView

Image

On

AnkiDroid AnkiDroid Version = 2.21alpha13-debug (7133b31bb51b26fa815972f99943fc59ea9dac61)
Backend Version = 0.1.51-anki25.02 (25.02 038d85b1d9e1896e93a3e4a26f600c79ddc33611)

I do not see progress in the WebView on Android, and the text is different

Image
Subject: [PATCH] fix: optimizing presets message
---
Index: AnkiDroid/src/main/java/com/ichi2/anki/pages/PostRequestHandler.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/pages/PostRequestHandler.kt b/AnkiDroid/src/main/java/com/ichi2/anki/pages/PostRequestHandler.kt
--- a/AnkiDroid/src/main/java/com/ichi2/anki/pages/PostRequestHandler.kt	(revision 7133b31bb51b26fa815972f99943fc59ea9dac61)
+++ b/AnkiDroid/src/main/java/com/ichi2/anki/pages/PostRequestHandler.kt	(date 1740398578537)
@@ -36,6 +36,7 @@
 import com.ichi2.libanki.getFieldNamesRaw
 import com.ichi2.libanki.getImportAnkiPackagePresetsRaw
 import com.ichi2.libanki.getNotetypeNamesRaw
+import com.ichi2.libanki.sched.computeFsrsParamsRaw
 import com.ichi2.libanki.sched.computeOptimalRetentionRaw
 import com.ichi2.libanki.sched.evaluateParamsRaw
 import com.ichi2.libanki.sched.simulateFsrsReviewRaw
@@ -122,7 +123,7 @@
                 withCol { updateImageOcclusionNoteRaw(bytes) }
             }
         },
-        "computeFsrsParams" to { bytes -> lifecycleScope.async { computeFsrsParams(bytes) } },
+        "computeFsrsParams" to { bytes -> lifecycleScope.async { withCol { computeFsrsParamsRaw(bytes) } } },
         "deckOptionsReady" to { bytes -> lifecycleScope.async { deckOptionsReady(bytes) } },
         "deckOptionsRequireClose" to { bytes -> lifecycleScope.async { deckOptionsRequireClose(bytes) } },
     )
Index: AnkiDroid/src/main/java/com/ichi2/anki/pages/DeckOptions.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/pages/DeckOptions.kt b/AnkiDroid/src/main/java/com/ichi2/anki/pages/DeckOptions.kt
--- a/AnkiDroid/src/main/java/com/ichi2/anki/pages/DeckOptions.kt	(revision 7133b31bb51b26fa815972f99943fc59ea9dac61)
+++ b/AnkiDroid/src/main/java/com/ichi2/anki/pages/DeckOptions.kt	(date 1740398578534)
@@ -38,7 +38,6 @@
 import com.ichi2.anki.withProgress
 import com.ichi2.annotations.NeedsTest
 import com.ichi2.libanki.DeckId
-import com.ichi2.libanki.sched.computeFsrsParamsRaw
 import com.ichi2.libanki.undoableOp
 import com.ichi2.libanki.updateDeckConfigsRaw
 import kotlinx.coroutines.Dispatchers
@@ -263,17 +262,6 @@
     return output
 }
 
-suspend fun FragmentActivity.computeFsrsParams(input: ByteArray): ByteArray =
-    withContext(Dispatchers.Main) {
-        withProgress(extractProgress = {
-            text = this.toUpdatingCardsString() ?: getString(R.string.dialog_processing)
-        }) {
-            withContext(Dispatchers.IO) {
-                withCol { computeFsrsParamsRaw(input) }
-            }
-        }
-    }
-
 /**
  * ```
  * Optimizing preset 1/20
@@ -301,24 +289,6 @@
     return label + "\n" + reviewsLabel
 }
 
-/**
- * ```
- * Updating Cards: 45/23687
- * ```
- *
- * @return the above string, or `null` if [ProgressContext] has no
- * [compute parameters][Progress.hasComputeParams]
- */
-private fun ProgressContext.toUpdatingCardsString(): String? {
-    if (!progress.hasComputeParams()) return null
-
-    val params = progress.computeParams
-    return TR.deckConfigUpdatingCards(
-        currentCardsCount = params.current,
-        totalCardsCount = params.total,
-    )
-}
-
 private fun FragmentActivity.requireDeckOptionsFragment(): DeckOptions {
     require(this is SingleFragmentActivity) { "activity must be SingleFragmentActivity" }
     return requireNotNull(this.fragment as? DeckOptions?) { "fragment must be DeckOptions" }

@david-allison david-allison removed their assignment Feb 24, 2025
@user1823
Copy link
Contributor Author

user1823 commented Feb 24, 2025

and the text is different

IIRC, the text is Optimize current preset in US English and the UK English version retains the older wording (Optimise) because the "translators" have not updated it. This is not that important, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants