From 37ea359931b5a6a5414edaecea36e3e4d1ef75e7 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Wed, 26 Oct 2011 12:19:12 +0900 Subject: [PATCH] add indices to upgrade check if missing --- anki/upgrade.py | 5 +++++ anki/utils.py | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/anki/upgrade.py b/anki/upgrade.py index 9b87c37b9..137736e38 100644 --- a/anki/upgrade.py +++ b/anki/upgrade.py @@ -53,6 +53,11 @@ class Upgrader(object): # old version? if db.scalar("select version from decks") != 65: return + # ensure we have indices for checks below + db.executescript(""" +create index if not exists ix_cards_factId on cards (factId); +create index if not exists ix_fields_factId on fieldModels (factId); +analyze;""") # fields missing a field model? if db.list(""" select id from fields where fieldModelId not in ( diff --git a/anki/utils.py b/anki/utils.py index 976484185..e75c3a8f6 100644 --- a/anki/utils.py +++ b/anki/utils.py @@ -193,6 +193,10 @@ def maxID(db): def guid64(): return random.randint(-sys.maxint-1, sys.maxint) +def guid32(): + max = 2**32 + return random.randint(0, max-1) + # Fields ##############################################################################