trigger the db progress handler after more operations

We originally were triggering on 100 opcodes, because at the time we were
doing write-heavy alterations to the DB for inactive tags, and a higher level
of opcodes would pause the interface for a long time. The query structure is
different now, so we can afford to save the overhead of more frequent calls.

With the change, a .reset() triggers the handler 3 times; fixIntegrity()
triggers it 30 times over a period of 4.5 seconds.
This commit is contained in:
Damien Elmes 2011-03-13 19:04:55 +09:00
parent 1dc3a0ad4a
commit f74d9b68fe
2 changed files with 6 additions and 11 deletions

View file

@ -71,3 +71,6 @@ class DB(object):
def close(self):
self._db.close()
def set_progress_handler(self, *args):
self._db.set_progress_handler(*args)

View file

@ -535,12 +535,6 @@ where c.fid == f.id and f.mid == m.id and c.gid = g.id
def tagList(self):
return self.db.list("select name from tags order by name")
def cardsWithNoTags(self):
return self.db.list("""
select cards.id from cards, facts where
facts.tags = ""
and cards.fid = facts.id""")
def cardHasTag(self, card, tag):
tags = self.db.scalar("select tags from fact where id = :fid",
fid=card.fid)
@ -630,16 +624,14 @@ update facts set tags = :t, mod = :n where id = :id""", [fix(row) for row in res
return
self.progressHandlerCalled = time.time()
if self.progressHandlerEnabled:
# things which hook on this should be very careful not to touch
# the db as they run
runHook("dbProgress")
def setupProgressHandler(self):
self.progressHandlerCalled = 0
self.progressHandlerEnabled = False
try:
self.engine.raw_connection().set_progress_handler(
deck.progressHandler, 100)
except:
pass
self.db.set_progress_handler(self.progressHandler, 100000)
def enableProgressHandler(self):
self.progressHandlerEnabled = True