add rebuild arg for minimal startup

this bypasses rebuilding the queue and other startup initialization and thus
loads the deck considerably faster. This is useful when you want to perform
operations on the deck like syncing, but don't need the ability to review
cards
This commit is contained in:
Damien Elmes 2010-12-08 15:28:28 +09:00
parent 044f28af5a
commit 05f60c49c8

View file

@ -3556,7 +3556,7 @@ backupDir = os.path.expanduser("~/.anki/backups")
class DeckStorage(object): class DeckStorage(object):
def Deck(path=None, backup=True, lock=True, pool=True): def Deck(path=None, backup=True, lock=True, pool=True, rebuild=True):
"Create a new deck or attach to an existing one." "Create a new deck or attach to an existing one."
create = True create = True
if path is None: if path is None:
@ -3571,9 +3571,9 @@ class DeckStorage(object):
try: try:
(engine, session) = DeckStorage._attach(sqlpath, create, pool) (engine, session) = DeckStorage._attach(sqlpath, create, pool)
s = session() s = session()
metadata.create_all(engine)
if create: if create:
ver = 999 ver = 999
metadata.create_all(engine)
deck = DeckStorage._init(s) deck = DeckStorage._init(s)
else: else:
ver = s.scalar("select version from decks limit 1") ver = s.scalar("select version from decks limit 1")
@ -3596,6 +3596,8 @@ class DeckStorage(object):
s.execute("alter table " + st) s.execute("alter table " + st)
except: except:
pass pass
if ver < DECK_VERSION:
metadata.create_all(engine)
deck = s.query(Deck).get(1) deck = s.query(Deck).get(1)
if not deck: if not deck:
raise DeckAccessError(_("Deck missing core table"), raise DeckAccessError(_("Deck missing core table"),
@ -3656,6 +3658,11 @@ class DeckStorage(object):
type="inuse") type="inuse")
else: else:
raise e raise e
if not rebuild:
# minimal startup
deck._globalStats = globalStats(deck)
deck._dailyStats = dailyStats(deck)
return deck
if needUnpack: if needUnpack:
deck.startProgress() deck.startProgress()
DeckStorage._addIndices(deck) DeckStorage._addIndices(deck)