diff --git a/anki/deck.py b/anki/deck.py index 1d892fbcd..100eacbe1 100644 --- a/anki/deck.py +++ b/anki/deck.py @@ -1750,15 +1750,9 @@ facts.modelId = :id""", id=modelId)) insert into cardTags (cardId, tagId, src) values (:cardId, :tagId, :src)""", d) - tags = self.s.column0("select id from tags") - unused = [] - for t in tags: - if not self.s.scalar( - "select 1 from cardTags where tagId = :d limit 1", - d=t): - unused.append(t) - self.s.statement(""" -delete from tags where id in %s and priority = 2""" % ids2str(unused)) + self.s.execute( + "delete from tags where priority = 2 and id not in "+ + "(select distinct tagId from cardTags)") def updateTagsForModel(self, model): cards = self.s.all("""