Skip to content

Commit abb4f54

Browse files
committed
fixed wrong priority file used during recalc (#319)
1 parent 9f41fc9 commit abb4f54

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

ankimorphs/ankimorphs_db.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -470,24 +470,39 @@ def get_card_morph_map_cache(self) -> dict[int, list[Morpheme]]:
470470
return card_morph_map_cache
471471

472472
def get_am_cards_data_dict(
473-
self, note_type_id: NotetypeId | None
473+
self,
474+
note_type_id: NotetypeId | None,
475+
include_tags: str, # whitespace separated string
476+
exclude_tags: str, # whitespace separated string
474477
) -> dict[CardId, AnkiMorphsCardData]:
475478
assert mw is not None
476479
assert mw.col.db is not None
477480
assert note_type_id is not None
478481

479-
result = self.con.execute(
480-
"""
482+
query = """
481483
SELECT card_id, note_id, note_type_id, card_type, tags
482484
FROM Cards
483485
WHERE note_type_id = ?
484-
""",
485-
(note_type_id,),
486-
).fetchall()
486+
"""
487+
488+
params: list[Any] = [note_type_id]
489+
490+
if len(include_tags) > 0:
491+
required_conditions = " AND ".join(["tags LIKE ?"] * len(include_tags))
492+
query += f" AND {required_conditions}"
493+
params.extend([f"% {tag} %" for tag in include_tags])
494+
495+
if len(exclude_tags) > 0:
496+
excluded_conditions = " AND ".join(["tags NOT LIKE ?"] * len(exclude_tags))
497+
query += f" AND {excluded_conditions}"
498+
params.extend([f"% {tag} %" for tag in exclude_tags])
499+
500+
result = self.con.execute(query, tuple(params)).fetchall()
487501

488502
am_db_row_data_dict: dict[CardId, AnkiMorphsCardData] = {}
489503
for am_data in map(AnkiMorphsCardData, result):
490504
am_db_row_data_dict[am_data.card_id] = am_data
505+
491506
return am_db_row_data_dict
492507

493508
# the cache needs to have a max size to maintain garbage collection

ankimorphs/ankimorphs_globals.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"""
66

77
# Semantic Versioning https://semver.org/
8-
__version__ = "4.0.0"
8+
__version__ = "4.0.1"
99

1010
DEV_MODE: bool = False
1111

ankimorphs/recalc/recalc_main.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,9 @@ def _update_cards_and_notes( # pylint:disable=too-many-locals, too-many-stateme
190190
)
191191
cards_data_dict: dict[CardId, AnkiMorphsCardData] = (
192192
am_db.get_am_cards_data_dict(
193-
note_type_id=model_manager.id_for_name(config_filter.note_type)
193+
note_type_id=model_manager.id_for_name(config_filter.note_type),
194+
include_tags=config_filter.tags["include"],
195+
exclude_tags=config_filter.tags["exclude"],
194196
)
195197
)
196198
card_amount = len(cards_data_dict)

0 commit comments

Comments
 (0)