Skip to content

Fix import dialog showing 0 notes/media for subdeck-only decks#255

Merged
aplaice merged 2 commits into
Stvad:masterfrom
fabiomanz:fix/import-dialog-subdeck-counts
Jun 22, 2026
Merged

Fix import dialog showing 0 notes/media for subdeck-only decks#255
aplaice merged 2 commits into
Stvad:masterfrom
fabiomanz:fix/import-dialog-subdeck-counts

Conversation

@fabiomanz

Copy link
Copy Markdown
Contributor

Summary

Fixes #190. The import dialog's "Notes:" and "Media Files:" counts were read directly from the top-level JSON arrays, so decks whose notes/media live only in subdecks displayed 0.

This matches the approach proposed in the issue: do the JSON→Deck conversion once, before showing the dialog, and let the dialog ask the Deck for the counts. This removes a coupling between the dialog and the on-disk JSON layout.

Changes

  • Deck: new get_media_file_count() parallel to the existing get_note_count(), plus a media_files field.
  • deck_initializer.from_json: populate deck.media_files from the JSON before post_import_filter strips the key.
  • anki_importer.load_deck: build the Deck up front and pass it to the dialog instead of the raw JSON.
  • ImportDialog: takes a Deck; note models are read from deck.metadata.models; counts come from the two get_*_count() methods.

Tests

  • test/representation/deck_spec.py (new) — unit tests for both count methods (flat, nested, subdeck-only).
  • test/representation/deck_initializer_spec.py — added an integration test verifying from_json populates media_files recursively.

Manual verification

Tested locally in Anki by importing a deck whose notes live only in a subdeck — the dialog now reports the correct counts instead of 0.

@fabiomanz
fabiomanz force-pushed the fix/import-dialog-subdeck-counts branch from a8e316a to 8b50f8f Compare June 16, 2026 19:42
Convert the deck from JSON before showing the import dialog so the
dialog can use Deck.get_note_count() and a new
Deck.get_media_file_count() to display counts recursively across
subdecks.

Closes Stvad#190
@fabiomanz
fabiomanz force-pushed the fix/import-dialog-subdeck-counts branch from 8b50f8f to 0825778 Compare June 20, 2026 10:44
@aplaice

aplaice commented Jun 21, 2026

Copy link
Copy Markdown
Collaborator

Thanks very much for this! (And thanks for patiently rebasing over master, multiple times...)

I'm sorry for the horrible delay replying and also for the multiple issues with our actions!

One slight issue is that it seems that if the same media files are present in multiple sub-decks (e.g. re-using the same media in multiple notes or having shared (_xxx) media) then I think we'll get an overcount. (Manual testing seems to confirm this.) (FWIW I think that using 'file' as the universal media filename in _make_deck, in the deck_spec test is an oversimplification, since if the filename is the same we should only really report a single media file.)

Otherwise, this looks great!

The same media file (re-used media or shared `_xxx` media) can appear
in multiple decks. Count unique filenames via a set instead of summing
per-deck counts, so shared/duplicated media is no longer overcounted.
@fabiomanz

Copy link
Copy Markdown
Contributor Author

Thanks for the feedback. Can you please take a look if the newest changes fulfill your questions?

@aplaice
aplaice merged commit 1d93f6b into Stvad:master Jun 22, 2026
2 checks passed
@aplaice

aplaice commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

Thanks very much!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Note count in import dialog doesn't include subdecks

2 participants