mirror of
https://github.com/ankitects/anki.git
synced 2025-11-07 13:17:12 -05:00
use tag cache for great speed increase in cram, allow card id limit
This commit is contained in:
parent
085fbf3bcc
commit
d09709fb50
1 changed files with 12 additions and 12 deletions
|
|
@ -15,12 +15,14 @@ from anki.cards import Card
|
||||||
from anki.sync import SyncClient, SyncServer, BulkMediaSyncer
|
from anki.sync import SyncClient, SyncServer, BulkMediaSyncer
|
||||||
from anki.lang import _
|
from anki.lang import _
|
||||||
from anki.utils import findTag, parseTags, stripHTML, ids2str
|
from anki.utils import findTag, parseTags, stripHTML, ids2str
|
||||||
|
from anki.tags import tagIds
|
||||||
from anki.db import *
|
from anki.db import *
|
||||||
|
|
||||||
class Exporter(object):
|
class Exporter(object):
|
||||||
def __init__(self, deck):
|
def __init__(self, deck):
|
||||||
self.deck = deck
|
self.deck = deck
|
||||||
self.limitTags = []
|
self.limitTags = []
|
||||||
|
self.limitCardIds = []
|
||||||
|
|
||||||
def exportInto(self, path):
|
def exportInto(self, path):
|
||||||
file = open(path, "wb")
|
file = open(path, "wb")
|
||||||
|
|
@ -35,21 +37,19 @@ class Exporter(object):
|
||||||
return text
|
return text
|
||||||
|
|
||||||
def cardIds(self):
|
def cardIds(self):
|
||||||
"Return all cards, limited by tags."
|
"Return all cards, limited by tags or provided ids."
|
||||||
tlist = self.deck.tagsList()
|
if self.limitCardIds:
|
||||||
cards = [id for (id, tags, pri) in tlist if self.hasTags(tags)]
|
return self.limitCardIds
|
||||||
|
if not self.limitTags:
|
||||||
|
cards = self.deck.s.column0("select id from cards")
|
||||||
|
else:
|
||||||
|
d = tagIds(self.deck.s, self.limitTags)
|
||||||
|
cards = self.deck.s.column0(
|
||||||
|
"select cardId from cardTags where tagid in %s" %
|
||||||
|
ids2str(d.values()))
|
||||||
self.count = len(cards)
|
self.count = len(cards)
|
||||||
return cards
|
return cards
|
||||||
|
|
||||||
def hasTags(self, tags):
|
|
||||||
tags = parseTags(tags)
|
|
||||||
if not self.limitTags:
|
|
||||||
return True
|
|
||||||
for tag in self.limitTags:
|
|
||||||
if findTag(tag, tags):
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
class AnkiExporter(Exporter):
|
class AnkiExporter(Exporter):
|
||||||
|
|
||||||
key = _("Anki decks (*.anki)")
|
key = _("Anki decks (*.anki)")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue