fix unit tests, turn off some debugging

This commit is contained in:
Damien Elmes 2009-02-19 17:27:13 +09:00
parent e4354181c4
commit 780010ad68
2 changed files with 29 additions and 24 deletions

View file

@ -735,10 +735,16 @@ and priority in (1,2,3,4) and type in (0, 1)""", time=time)
new) new)
return new return new
def updateAllPriorities(self, extraExcludes=[], where=""): def updateAllPriorities(self, extraExcludes=[], where="", force=False):
"Update all card priorities if changed." "Update all card priorities if changed."
t = time.time()
new = self.updateTagPriorities() new = self.updateTagPriorities()
# if any tag priorities have changed, update cards if force:
new = self.s.all("select id, priority as pri from tags")
self.updateAllPrioritiesForTags(new)
#print "update all", time.time() - t
def updateAllPrioritiesForTags(self, new):
if new: if new:
seen = {} seen = {}
for c in (0, 4, 3, 1, 2): for c in (0, 4, 3, 1, 2):
@ -755,23 +761,27 @@ where id in %s""" % ids2str(ids), c=c)
"update cards set isDue = 0 where type in (0,1,2) and " "update cards set isDue = 0 where type in (0,1,2) and "
"priority = 0 and isDue = 1") "priority = 0 and isDue = 1")
def updatePriorities(self, cardIds):
t = time.time()
cards = self.s.all("""
select cardTags.cardId,
case min(tags.priority) when 0 then 0 else max(tags.priority) end
from cardTags, tags
where cardTags.tagId = tags.id
and cardTags.cardId in %s
group by cardTags.cardId""" % ids2str(cardIds))
self.s.statements(
"update cards set priority = :pri where id = :id",
[{'id': c[0], 'pri': c[1]} for c in cards])
self.s.execute(
"update cards set isDue = 0 where type in (0,1,2) and "
"priority = 0 and isDue = 1")
#print "update cards", time.time() - t
def updatePriority(self, card): def updatePriority(self, card):
"Update priority on a single card." "Update priority on a single card."
raise "nyi" self.s.flush()
tagCache = self.genTagCache() self.updatePriorities([card.id])
tags = (card.tags + "," + card.fact.tags + "," +
card.fact.model.tags + "," + card.cardModel.name)
p = self.priorityFromTagString(tags, tagCache)
if p != card.priority:
card.priority = p
if p == 0:
card.isDue = 0
self.s.flush()
def updatePriorities(self, cardIds):
raise "nyi"
self.updateAllPriorities(
where=" and cards.id in %s" % ids2str(cardIds))
# Card/fact counts - all in deck, not just due # Card/fact counts - all in deck, not just due
########################################################################## ##########################################################################
@ -1437,7 +1447,6 @@ and cards.factId = facts.id""")
# get ids # get ids
for tag in tagStr.split(): for tag in tagStr.split():
tag = tag.replace("*", "%") tag = tag.replace("*", "%")
print tag
if "%" in tag: if "%" in tag:
ids = self.s.column0( ids = self.s.column0(
"select id from tags where tag like :tag", tag=tag) "select id from tags where tag like :tag", tag=tag)
@ -1452,7 +1461,6 @@ and cards.factId = facts.id""")
tagIds.append(id) tagIds.append(id)
# search for any # search for any
if search == "or": if search == "or":
print tagIds
return self.s.column0( return self.s.column0(
"select cardId from cardTags where tagId in %s" % "select cardId from cardTags where tagId in %s" %
ids2str(tagIds)) ids2str(tagIds))
@ -1467,7 +1475,6 @@ and cards.factId = facts.id""")
l.append("select cardId from cardTags where tagId = %d" % l.append("select cardId from cardTags where tagId = %d" %
ids) ids)
q = " intersect ".join(l) q = " intersect ".join(l)
print q
return self.s.column0(q) return self.s.column0(q)
def allTags(self): def allTags(self):
@ -1503,7 +1510,6 @@ cards.factId = facts.id and
facts.modelId = :id""", id=modelId)) facts.modelId = :id""", id=modelId))
def updateCardTags(self, cardIds=None): def updateCardTags(self, cardIds=None):
print "called"
self.s.flush() self.s.flush()
t = time.time() t = time.time()
if cardIds is None: if cardIds is None:
@ -1535,11 +1541,11 @@ facts.modelId = :id""", id=modelId))
d.append({"cardId": id, d.append({"cardId": id,
"tagId": tids[tag.lower()], "tagId": tids[tag.lower()],
"src": 2}) "src": 2})
self.s.statements(""" if d:
self.s.statements("""
insert into cardTags insert into cardTags
(cardId, tagId, src) values (cardId, tagId, src) values
(:cardId, :tagId, :src)""", d) (:cardId, :tagId, :src)""", d)
print "small tag", time.time() - t
# Tags: adding/removing in bulk # Tags: adding/removing in bulk
########################################################################## ##########################################################################

View file

@ -19,7 +19,6 @@ from anki.db import *
########################################################################## ##########################################################################
def initTagTables(s): def initTagTables(s):
print "init"
s.statement(""" s.statement("""
create table tags ( create table tags (
id integer not null, id integer not null,