Stvad / CrowdAnki

Plugin for Anki SRS designed to facilitate cooperation on creation of notes and decks.
MIT License
520 stars 44 forks source link

Note count in import dialog doesn't include subdecks #190

Open aplaice opened 1 year ago

aplaice commented 1 year ago

(Low priority.)

To reproduce:

  1. Import the following minimal deck with one subdeck and one card in the subdeck (and no cards in the main deck):
```json { "__type__": "Deck", "children": [ { "__type__": "Deck", "children": [], "crowdanki_uuid": "12684a9e-b15b-11ed-985f-c9e14aaf9362", "deck_config_uuid": "12684f30-b15b-11ed-985f-c9e14aaf9362", "desc": "", "dyn": 0, "extendNew": 0, "extendRev": 0, "media_files": [], "name": "subdeck", "newLimit": null, "newLimitToday": null, "notes": [ { "__type__": "Note", "fields": [ "a", "b" ], "guid": "XRzqD(ea!", "note_model_uuid": "22b980ca-b15b-11ed-b503-c5b4cccbc2bf", "tags": [] } ], "reviewLimit": null, "reviewLimitToday": null } ], "crowdanki_uuid": "1268232a-b15b-11ed-985f-c9e14aaf9362", "deck_config_uuid": "12684f30-b15b-11ed-985f-c9e14aaf9362", "deck_configurations": [ { "__type__": "DeckConfig", "autoplay": true, "buryInterdayLearning": false, "crowdanki_uuid": "12684f30-b15b-11ed-985f-c9e14aaf9362", "dyn": false, "interdayLearningMix": 0, "lapse": { "delays": [ 10.0 ], "leechAction": 1, "leechFails": 8, "minInt": 1, "mult": 0.0 }, "maxTaken": 60, "name": "Default", "new": { "bury": false, "delays": [ 1.0, 10.0 ], "initialFactor": 2500, "ints": [ 1, 4, 0 ], "order": 1, "perDay": 20 }, "newGatherPriority": 0, "newMix": 0, "newPerDayMinimum": 0, "newSortOrder": 0, "replayq": true, "rev": { "bury": false, "ease4": 1.3, "hardFactor": 1.2, "ivlFct": 1.0, "maxIvl": 36500, "perDay": 200 }, "reviewOrder": 0, "timer": 0 } ], "desc": "", "dyn": 0, "extendNew": 0, "extendRev": 0, "media_files": [], "name": "Default", "newLimit": null, "newLimitToday": null, "note_models": [ { "__type__": "NoteModel", "crowdanki_uuid": "22b980ca-b15b-11ed-b503-c5b4cccbc2bf", "css": ".card {\n font-family: arial;\n font-size: 20px;\n text-align: center;\n color: black;\n background-color: white;\n}\n", "flds": [ { "collapsed": false, "description": "", "font": "Arial", "name": "Front", "ord": 0, "plainText": false, "rtl": false, "size": 20, "sticky": false }, { "collapsed": false, "description": "", "font": "Arial", "name": "Back", "ord": 1, "plainText": false, "rtl": false, "size": 20, "sticky": false } ], "latexPost": "\\end{document}", "latexPre": "\\documentclass[12pt]{article}\n\\special{papersize=3in,5in}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amssymb,amsmath}\n\\pagestyle{empty}\n\\setlength{\\parindent}{0in}\n\\begin{document}\n", "latexsvg": false, "name": "Basic", "req": [ [ 0, "any", [ 0 ] ] ], "sortf": 0, "tmpls": [ { "afmt": "{{FrontSide}}\n\n
\n\n{{Back}}", "bafmt": "", "bfont": "", "bqfmt": "", "bsize": 0, "did": null, "name": "Card 1", "ord": 0, "qfmt": "{{Front}}" } ], "type": 0 } ], "notes": [], "reviewLimit": null, "reviewLimitToday": null } ```
  1. Read the import dialog.

Expected behaviour

The "Deck Parts to Use" says:

Notes: 1.

Actual behaviour

The "Deck Parts to Use" says:

Notes: 0.

This is because we currently only check in the main deck itself.

If we had a CrowdAnki deck object (rather than a pure JSON), we could use the deck.get_note_count function, so perhaps we should carry out the "deck initialization from JSON" (i.e. the conversion from JSON to "internal CrowdAnki object") before showing the dialog?

This conversion itself doesn't touch the user's collection, we don't use any information from the import dialog in this conversion and there's nothing in the final CrowdAnki deck object that's not in the initial JSON. Also, the earlier we do the conversion, the less dependent we're on the specifics of the JSON implementation if we end up having alternative storage formats.

The main con might be that the conversion might be slow? (I don't think it is — AFAIU most of our slowness comes from interfacing with the Anki database — i.e. converting from our internal object to Anki's.)

(I believe the same applies to media counts.)

ohare93 commented 1 year ago

Yea, seems this was missed (by me!). Should be an easy fix though, and I don't think it will be too slow 👍