mirror of
https://github.com/ankitects/anki.git
synced 2025-09-21 23:42:23 -04:00
refactor facts table
- spaceUntil->cache - remove obsolete lastCardId
This commit is contained in:
parent
d9c0fba171
commit
edd8f79ab9
3 changed files with 16 additions and 10 deletions
|
@ -776,7 +776,6 @@ limit %s""" % (self.cramOrder, self.queueLimit)))
|
||||||
# only update if card was not new
|
# only update if card was not new
|
||||||
card.lastDue = card.due
|
card.lastDue = card.due
|
||||||
card.due = self.nextDue(card, ease, oldState)
|
card.due = self.nextDue(card, ease, oldState)
|
||||||
card.spaceUntil = 0
|
|
||||||
if not self.finishScheduler:
|
if not self.finishScheduler:
|
||||||
# don't update factor in custom schedulers
|
# don't update factor in custom schedulers
|
||||||
self.updateFactor(card, ease)
|
self.updateFactor(card, ease)
|
||||||
|
@ -1895,7 +1894,7 @@ order by fields.factId""" % ids2str([x[2] for x in ids])),
|
||||||
for a in all:
|
for a in all:
|
||||||
r.append({'id':a[0], 'v':stripHTMLMedia(a[1])})
|
r.append({'id':a[0], 'v':stripHTMLMedia(a[1])})
|
||||||
self.db.statements(
|
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):
|
def rebuildCardOrdinals(self, ids):
|
||||||
"Update all card models in IDS. Caller must update model modtime."
|
"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("*", "%")
|
token = token.replace("*", "%")
|
||||||
args["_ff_%d" % c] = "%"+token+"%"
|
args["_ff_%d" % c] = "%"+token+"%"
|
||||||
fquery += """
|
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,
|
return (tquery, fquery, qquery, fidquery, cmquery, sfquery,
|
||||||
qaquery, showdistinct, filters, args)
|
qaquery, showdistinct, filters, args)
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,9 @@ mapper(Field, fieldsTable, properties={
|
||||||
|
|
||||||
# Facts: a set of fields and a model
|
# 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(
|
factsTable = Table(
|
||||||
'facts', metadata,
|
'facts', metadata,
|
||||||
|
@ -51,11 +53,7 @@ factsTable = Table(
|
||||||
Column('created', Float, nullable=False, default=time.time),
|
Column('created', Float, nullable=False, default=time.time),
|
||||||
Column('modified', Float, nullable=False, default=time.time),
|
Column('modified', Float, nullable=False, default=time.time),
|
||||||
Column('tags', UnicodeText, nullable=False, default=u""),
|
Column('tags', UnicodeText, nullable=False, default=u""),
|
||||||
# spaceUntil is reused as a html-stripped cache of the fields
|
Column('cache', UnicodeText, nullable=False, default=u""))
|
||||||
Column('spaceUntil', UnicodeText, nullable=False, default=u""),
|
|
||||||
# obsolete
|
|
||||||
Column('lastCardId', Integer, ForeignKey(
|
|
||||||
"cards.id", use_alter=True, name="lastCardIdfk")))
|
|
||||||
|
|
||||||
class Fact(object):
|
class Fact(object):
|
||||||
"A single fact. Fields exposed as dict interface."
|
"A single fact. Fields exposed as dict interface."
|
||||||
|
@ -143,7 +141,7 @@ class Fact(object):
|
||||||
ankiqt.setModWarningShown = True
|
ankiqt.setModWarningShown = True
|
||||||
deck = ankiqt.mw.deck
|
deck = ankiqt.mw.deck
|
||||||
assert deck
|
assert deck
|
||||||
self.spaceUntil = stripHTMLMedia(u" ".join(
|
self.cache = stripHTMLMedia(u" ".join(
|
||||||
self.values()))
|
self.values()))
|
||||||
for card in self.cards:
|
for card in self.cards:
|
||||||
card.rebuildQA(deck)
|
card.rebuildQA(deck)
|
||||||
|
|
|
@ -49,6 +49,15 @@ due, factor, reps, successive, noCount from cards2""")
|
||||||
insert or ignore into cardTags select cardId, tagId, src from cardTags2""")
|
insert or ignore into cardTags select cardId, tagId, src from cardTags2""")
|
||||||
s.execute("drop table tags2")
|
s.execute("drop table tags2")
|
||||||
s.execute("drop table cardTags2")
|
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
|
return ver
|
||||||
|
|
||||||
def updateIndices(deck):
|
def updateIndices(deck):
|
||||||
|
|
Loading…
Reference in a new issue