From 05f60c49c8dfd513accd7eb8b1993df06a0d0c52 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Wed, 8 Dec 2010 15:28:28 +0900 Subject: [PATCH] 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 --- anki/deck.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/anki/deck.py b/anki/deck.py index 51b3d58bd..b51492977 100644 --- a/anki/deck.py +++ b/anki/deck.py @@ -3556,7 +3556,7 @@ backupDir = os.path.expanduser("~/.anki/backups") 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 = True if path is None: @@ -3571,9 +3571,9 @@ class DeckStorage(object): try: (engine, session) = DeckStorage._attach(sqlpath, create, pool) s = session() - metadata.create_all(engine) if create: ver = 999 + metadata.create_all(engine) deck = DeckStorage._init(s) else: ver = s.scalar("select version from decks limit 1") @@ -3596,6 +3596,8 @@ class DeckStorage(object): s.execute("alter table " + st) except: pass + if ver < DECK_VERSION: + metadata.create_all(engine) deck = s.query(Deck).get(1) if not deck: raise DeckAccessError(_("Deck missing core table"), @@ -3656,6 +3658,11 @@ class DeckStorage(object): type="inuse") else: raise e + if not rebuild: + # minimal startup + deck._globalStats = globalStats(deck) + deck._dailyStats = dailyStats(deck) + return deck if needUnpack: deck.startProgress() DeckStorage._addIndices(deck)