Use new backend filters in rename_tag()

This commit is contained in:
abdo 2021-01-16 18:49:01 +03:00
parent 34245e6f72
commit bf0086d565

View file

@ -16,6 +16,7 @@ import re
from typing import Collection, List, Optional, Sequence, Tuple from typing import Collection, List, Optional, Sequence, Tuple
import anki # pylint: disable=unused-import import anki # pylint: disable=unused-import
from anki.rsbackend import FilterToSearchIn
from anki.utils import ids2str from anki.utils import ids2str
@ -86,11 +87,11 @@ class TagManager:
def rename_tag(self, old: str, new: str) -> int: def rename_tag(self, old: str, new: str) -> int:
"Rename provided tag, returning number of changed notes." "Rename provided tag, returning number of changed notes."
escaped_name = re.sub(r"[*_\\]", r"\\\g<0>", old) search = self.col.backend.filter_to_search(FilterToSearchIn(tag=old))
quote_escaped = escaped_name.replace('"', '\\"') nids = self.col.find_notes(search)
nids = self.col.find_notes(f'tag:"{quote_escaped}"')
if not nids: if not nids:
return 0 return 0
escaped_name = re.sub(r"[*_\\]", r"\\\g<0>", old)
return self.bulk_update(nids, escaped_name, new, False) return self.bulk_update(nids, escaped_name, new, False)
# legacy routines # legacy routines