mirror of
https://github.com/ankitects/anki.git
synced 2025-09-21 23:42:23 -04:00
greatly improve import speed on large decks, randomize too
This commit is contained in:
parent
d1a44e308e
commit
155de15101
1 changed files with 14 additions and 4 deletions
|
@ -20,6 +20,7 @@ from anki.lang import _
|
||||||
from anki.utils import genID, canonifyTags
|
from anki.utils import genID, canonifyTags
|
||||||
from anki.errors import *
|
from anki.errors import *
|
||||||
from anki.utils import canonifyTags
|
from anki.utils import canonifyTags
|
||||||
|
from anki.deck import NEW_CARDS_RANDOM
|
||||||
|
|
||||||
# Base importer
|
# Base importer
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
@ -47,14 +48,21 @@ class Importer(object):
|
||||||
|
|
||||||
def doImport(self):
|
def doImport(self):
|
||||||
"Import."
|
"Import."
|
||||||
self.deck.startProgress(7)
|
random = self.deck.newCardOrder == NEW_CARDS_RANDOM
|
||||||
|
num = 7
|
||||||
|
if random:
|
||||||
|
num += 1
|
||||||
|
self.deck.startProgress(num)
|
||||||
self.deck.updateProgress(_("Importing..."))
|
self.deck.updateProgress(_("Importing..."))
|
||||||
c = self.foreignCards()
|
c = self.foreignCards()
|
||||||
self.importCards(c)
|
self.importCards(c)
|
||||||
self.deck.updateProgress()
|
self.deck.updateProgress()
|
||||||
self.deck.updateCardTags()
|
self.deck.updateCardTags(self.cardIds)
|
||||||
self.deck.updateProgress()
|
self.deck.updateProgress()
|
||||||
self.deck.updateAllPriorities()
|
self.deck.updatePriorities(self.cardIds)
|
||||||
|
if random:
|
||||||
|
self.deck.updateProgress()
|
||||||
|
self.deck.randomizeNewCards(self.cardIds)
|
||||||
self.deck.finishProgress()
|
self.deck.finishProgress()
|
||||||
if c:
|
if c:
|
||||||
self.deck.setModified()
|
self.deck.setModified()
|
||||||
|
@ -124,6 +132,7 @@ all but one card template."""))
|
||||||
|
|
||||||
def addCards(self, cards):
|
def addCards(self, cards):
|
||||||
"Add facts in bulk from foreign cards."
|
"Add facts in bulk from foreign cards."
|
||||||
|
self.cardIds = []
|
||||||
# map tags field to attr
|
# map tags field to attr
|
||||||
try:
|
try:
|
||||||
idx = self.mapping.index(0)
|
idx = self.mapping.index(0)
|
||||||
|
@ -175,7 +184,7 @@ where factId in (%s)""" % ",".join([str(s) for s in factIds]))
|
||||||
self.deck.s.execute(cardsTable.insert(),
|
self.deck.s.execute(cardsTable.insert(),
|
||||||
data)
|
data)
|
||||||
self.deck.updateProgress()
|
self.deck.updateProgress()
|
||||||
self.deck.updateCardsFromModel(self.model)
|
self.deck.updateCardsFromFactIds(factIds)
|
||||||
self.deck.cardCount += len(cards)
|
self.deck.cardCount += len(cards)
|
||||||
self.total = len(factIds)
|
self.total = len(factIds)
|
||||||
|
|
||||||
|
@ -188,6 +197,7 @@ where factId in (%s)""" % ",".join([str(s) for s in factIds]))
|
||||||
data['due'] = self._now
|
data['due'] = self._now
|
||||||
self._now += .00001
|
self._now += .00001
|
||||||
data.update(card.__dict__)
|
data.update(card.__dict__)
|
||||||
|
self.cardIds.append(data['id'])
|
||||||
data['combinedDue'] = data['due']
|
data['combinedDue'] = data['due']
|
||||||
data['isDue'] = data['combinedDue'] < time.time()
|
data['isDue'] = data['combinedDue'] < time.time()
|
||||||
return data
|
return data
|
||||||
|
|
Loading…
Reference in a new issue