remove support for inactive tags

Unlike active tags, they are not able to be implemented efficiently, and they
duplicate the functionality of manually suspending cards
This commit is contained in:
Damien Elmes 2010-10-29 21:17:33 +09:00
parent 2967819882
commit cc8f619458

View file

@ -151,14 +151,12 @@ class Deck(object):
self.lastSessionStart = 0 self.lastSessionStart = 0
self.queueLimit = 200 self.queueLimit = 200
# if most recent deck var not defined, make sure defaults are set # if most recent deck var not defined, make sure defaults are set
if not self.s.scalar("select 1 from deckVars where key = 'revInactive'"): if not self.s.scalar("select 1 from deckVars where key = 'revActive'"):
self.setVarDefault("suspendLeeches", True) self.setVarDefault("suspendLeeches", True)
self.setVarDefault("leechFails", 16) self.setVarDefault("leechFails", 16)
self.setVarDefault("perDay", True) self.setVarDefault("perDay", True)
self.setVarDefault("newActive", "") self.setVarDefault("newActive", "")
self.setVarDefault("revActive", "") self.setVarDefault("revActive", "")
self.setVarDefault("newInactive", self.suspended)
self.setVarDefault("revInactive", self.suspended)
self.updateCutoff() self.updateCutoff()
self.setupStandardScheduler() self.setupStandardScheduler()
@ -198,42 +196,36 @@ class Deck(object):
self.rebuildRevCount() self.rebuildRevCount()
self.rebuildNewCount() self.rebuildNewCount()
def cardLimit(self, active, inactive, sql): def cardLimit(self, active, sql):
yes = parseTags(self.getVar(active)) yes = parseTags(self.getVar(active))
no = parseTags(self.getVar(inactive))
if yes: if yes:
yids = tagIds(self.s, yes).values() yids = tagIds(self.s, yes).values()
nids = tagIds(self.s, no).values() return sql.replace(
repl = ( "where ",
"c.id = ct.cardId and tagId in %s and " "where +c.id in (select cardId from cardTags where "
"tagId not in %s and ") % (ids2str(yids), ids2str(nids)) "tagId in %s) and " % ids2str(yids))
elif no:
nids = tagIds(self.s, no).values()
repl = "c.id = ct.cardId and tagId not in %s and " % ids2str(nids)
else: else:
return sql return sql
return sql.replace("from cards c where",
"from cards c, cardTags ct where " + repl)
def _rebuildFailedCount(self): def _rebuildFailedCount(self):
self.failedSoonCount = self.s.scalar( self.failedSoonCount = self.s.scalar(
self.cardLimit( self.cardLimit(
"revActive", "revInactive", "revActive",
"select count(distinct c.id) from cards c where type = 0 " "select count(*) from cards c where type = 0 "
"and combinedDue < :lim"), lim=self.dueCutoff) "and combinedDue < :lim"), lim=self.dueCutoff)
def _rebuildRevCount(self): def _rebuildRevCount(self):
self.revCount = self.s.scalar( self.revCount = self.s.scalar(
self.cardLimit( self.cardLimit(
"revActive", "revInactive", "revActive",
"select count(distinct c.id) from cards c where type = 1 " "select count(*) from cards c where type = 1 "
"and combinedDue < :lim"), lim=self.dueCutoff) "and combinedDue < :lim"), lim=self.dueCutoff)
def _rebuildNewCount(self): def _rebuildNewCount(self):
self.newCount = self.s.scalar( self.newCount = self.s.scalar(
self.cardLimit( self.cardLimit(
"newActive", "newInactive", "newActive",
"select count(distinct c.id) from cards c where type = 2 " "select count(*) from cards c where type = 2 "
"and combinedDue < :lim"), lim=self.dueCutoff) "and combinedDue < :lim"), lim=self.dueCutoff)
self.updateNewCountToday() self.updateNewCountToday()
@ -246,8 +238,8 @@ class Deck(object):
if self.failedSoonCount and not self.failedQueue: if self.failedSoonCount and not self.failedQueue:
self.failedQueue = self.s.all( self.failedQueue = self.s.all(
self.cardLimit( self.cardLimit(
"revActive", "revInactive", """ "revActive", """
select distinct c.id, factId, combinedDue from cards c where select c.id, factId, combinedDue from cards c where
type = 0 and combinedDue < :lim order by combinedDue type = 0 and combinedDue < :lim order by combinedDue
limit %d""" % self.queueLimit), lim=self.dueCutoff) limit %d""" % self.queueLimit), lim=self.dueCutoff)
self.failedQueue.reverse() self.failedQueue.reverse()
@ -256,8 +248,8 @@ limit %d""" % self.queueLimit), lim=self.dueCutoff)
if self.revCount and not self.revQueue: if self.revCount and not self.revQueue:
self.revQueue = self.s.all( self.revQueue = self.s.all(
self.cardLimit( self.cardLimit(
"revActive", "revInactive", """ "revActive", """
select distinct c.id, factId from cards c where select c.id, factId from cards c where
type = 1 and combinedDue < :lim order by %s type = 1 and combinedDue < :lim order by %s
limit %d""" % (self.revOrder(), self.queueLimit)), lim=self.dueCutoff) limit %d""" % (self.revOrder(), self.queueLimit)), lim=self.dueCutoff)
self.revQueue.reverse() self.revQueue.reverse()
@ -266,8 +258,8 @@ limit %d""" % (self.revOrder(), self.queueLimit)), lim=self.dueCutoff)
if self.newCount and not self.newQueue: if self.newCount and not self.newQueue:
self.newQueue = self.s.all( self.newQueue = self.s.all(
self.cardLimit( self.cardLimit(
"newActive", "newInactive", """ "newActive", """
select distinct c.id, factId from cards c where select c.id, factId from cards c where
type = 2 and combinedDue < :lim order by %s type = 2 and combinedDue < :lim order by %s
limit %d""" % (self.newOrder(), self.queueLimit)), lim=self.dueCutoff) limit %d""" % (self.newOrder(), self.queueLimit)), lim=self.dueCutoff)
self.newQueue.reverse() self.newQueue.reverse()
@ -1001,11 +993,10 @@ At this time tomorrow:<br>
This may be in the past if the deck is not finished. This may be in the past if the deck is not finished.
If the deck has no (enabled) cards, return None. If the deck has no (enabled) cards, return None.
Ignore new cards.""" Ignore new cards."""
return self.s.scalar(""" return self.s.scalar(self.cardLimit("revActive", """
select combinedDue from cards where type in (0,1) select combinedDue from cards c where type in (0,1)
%s
order by combinedDue order by combinedDue
limit 1""" % (self.cardLimit("revActive", "revInactive"))) limit 1"""))
def earliestTimeStr(self, next=None): def earliestTimeStr(self, next=None):
"""Return the relative time to the earliest card as a string.""" """Return the relative time to the earliest card as a string."""
@ -1036,13 +1027,13 @@ and type in (0, 1)""", time=time)
spaceSusp += ngettext('There is %d suspended card.', spaceSusp += ngettext('There is %d suspended card.',
'There are %d suspended cards.', 'There are %d suspended cards.',
c2) % c2 c2) % c2
c3 = self.inactiveCardCount() # c3 = self.inactiveCardCount()
if c3: # if c3:
if spaceSusp: # if spaceSusp:
spaceSusp += "<br>" # spaceSusp += "<br>"
spaceSusp += ngettext('There is %d inactive card.', # spaceSusp += ngettext('There is %d inactive card.',
'There are %d inactive cards.', # 'There are %d inactive cards.',
c3) % c3 # c3) % c3
c4 = self.leechCardCount() c4 = self.leechCardCount()
if c4: if c4:
if spaceSusp: if spaceSusp:
@ -1179,10 +1170,6 @@ where type in (3,4,5) and id in %s""" %
return self.s.scalar(""" return self.s.scalar("""
select count(id) from cards where priority = -3""") select count(id) from cards where priority = -3""")
def inactiveCardCount(self):
return self.s.scalar("""
select count(id) from cards where priority = 0""")
def leechCardCount(self): def leechCardCount(self):
return len(self.findCards("is:suspended tag:leech")) return len(self.findCards("is:suspended tag:leech"))