From edd8f79ab935be627767649d1d0b1a24df4879e3 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Tue, 22 Feb 2011 05:33:12 +0900 Subject: [PATCH] refactor facts table - spaceUntil->cache - remove obsolete lastCardId --- anki/deck.py | 5 ++--- anki/facts.py | 12 +++++------- anki/upgrade.py | 9 +++++++++ 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/anki/deck.py b/anki/deck.py index 5483a5e01..969334206 100644 --- a/anki/deck.py +++ b/anki/deck.py @@ -776,7 +776,6 @@ limit %s""" % (self.cramOrder, self.queueLimit))) # only update if card was not new card.lastDue = card.due card.due = self.nextDue(card, ease, oldState) - card.spaceUntil = 0 if not self.finishScheduler: # don't update factor in custom schedulers self.updateFactor(card, ease) @@ -1895,7 +1894,7 @@ order by fields.factId""" % ids2str([x[2] for x in ids])), for a in all: r.append({'id':a[0], 'v':stripHTMLMedia(a[1])}) self.db.statements( - "update facts set spaceUntil=:v where id=:id", r) + "update facts set cache=:v where id=:id", r) def rebuildCardOrdinals(self, ids): "Update all card models in IDS. Caller must update model modtime." @@ -2667,7 +2666,7 @@ select id from cards where answer like :_ff_%d escape '\\'""" % c token = token.replace("*", "%") args["_ff_%d" % c] = "%"+token+"%" fquery += """ -select id from facts where spaceUntil like :_ff_%d escape '\\'""" % c +select id from facts where cache like :_ff_%d escape '\\'""" % c return (tquery, fquery, qquery, fidquery, cmquery, sfquery, qaquery, showdistinct, filters, args) diff --git a/anki/facts.py b/anki/facts.py index 524776e1a..e3ef84e82 100644 --- a/anki/facts.py +++ b/anki/facts.py @@ -42,7 +42,9 @@ mapper(Field, fieldsTable, properties={ # Facts: a set of fields and a model ########################################################################## -# mapped in cards.py + +# Cache: a HTML-stripped amalgam of the field contents, so we can perform +# searches of marked up text in a reasonable time. factsTable = Table( 'facts', metadata, @@ -51,11 +53,7 @@ factsTable = Table( Column('created', Float, nullable=False, default=time.time), Column('modified', Float, nullable=False, default=time.time), Column('tags', UnicodeText, nullable=False, default=u""), - # spaceUntil is reused as a html-stripped cache of the fields - Column('spaceUntil', UnicodeText, nullable=False, default=u""), - # obsolete - Column('lastCardId', Integer, ForeignKey( - "cards.id", use_alter=True, name="lastCardIdfk"))) + Column('cache', UnicodeText, nullable=False, default=u"")) class Fact(object): "A single fact. Fields exposed as dict interface." @@ -143,7 +141,7 @@ class Fact(object): ankiqt.setModWarningShown = True deck = ankiqt.mw.deck assert deck - self.spaceUntil = stripHTMLMedia(u" ".join( + self.cache = stripHTMLMedia(u" ".join( self.values())) for card in self.cards: card.rebuildQA(deck) diff --git a/anki/upgrade.py b/anki/upgrade.py index 7284caf3c..49eadadae 100644 --- a/anki/upgrade.py +++ b/anki/upgrade.py @@ -49,6 +49,15 @@ due, factor, reps, successive, noCount from cards2""") insert or ignore into cardTags select cardId, tagId, src from cardTags2""") s.execute("drop table tags2") s.execute("drop table cardTags2") + # migrate facts + moveTable(s, "facts") + import facts + metadata.create_all(engine, tables=[facts.factsTable]) + # move data across + s.execute(""" +insert or ignore into facts select id, modelId, created, modified, tags, +spaceUntil from facts2""") + s.execute("drop table facts2") return ver def updateIndices(deck):