mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 08:46:37 -04:00
optimize updatePriorities(), get a 2-3x speedup
This commit is contained in:
parent
6893d01458
commit
57b659ca36
1 changed files with 15 additions and 6 deletions
21
anki/deck.py
21
anki/deck.py
|
@ -757,7 +757,8 @@ and priority in (1,2,3,4) and type in (0, 1)""", time=time)
|
||||||
new = self.updateTagPriorities()
|
new = self.updateTagPriorities()
|
||||||
if not partial:
|
if not partial:
|
||||||
new = self.s.all("select id, priority as pri from tags")
|
new = self.s.all("select id, priority as pri from tags")
|
||||||
cids = self.s.column0("select cardId from cardTags where tagId in %s" %
|
cids = self.s.column0(
|
||||||
|
"select distinct cardId from cardTags where tagId in %s" %
|
||||||
ids2str([x['id'] for x in new]))
|
ids2str([x['id'] for x in new]))
|
||||||
self.updatePriorities(cids, dirty=dirty)
|
self.updatePriorities(cids, dirty=dirty)
|
||||||
|
|
||||||
|
@ -793,6 +794,10 @@ and priority in (1,2,3,4) and type in (0, 1)""", time=time)
|
||||||
self.s.statement(
|
self.s.statement(
|
||||||
"update tags set priority = 0 where id in %s" %
|
"update tags set priority = 0 where id in %s" %
|
||||||
ids2str(ids.values()))
|
ids2str(ids.values()))
|
||||||
|
if len(cardIds) > 1000:
|
||||||
|
limit = ""
|
||||||
|
else:
|
||||||
|
limit = "and cardTags.cardId in %s" % ids2str(cardIds)
|
||||||
cards = self.s.all("""
|
cards = self.s.all("""
|
||||||
select cardTags.cardId,
|
select cardTags.cardId,
|
||||||
case
|
case
|
||||||
|
@ -802,15 +807,19 @@ when min(tags.priority) = 1 then 1
|
||||||
else 2 end
|
else 2 end
|
||||||
from cardTags, tags
|
from cardTags, tags
|
||||||
where cardTags.tagId = tags.id
|
where cardTags.tagId = tags.id
|
||||||
and cardTags.cardId in %s
|
%s
|
||||||
group by cardTags.cardId""" % ids2str(cardIds))
|
group by cardTags.cardId""" % limit)
|
||||||
if dirty:
|
if dirty:
|
||||||
extra = ", modified = :m "
|
extra = ", modified = :m "
|
||||||
else:
|
else:
|
||||||
extra = ""
|
extra = ""
|
||||||
self.s.statements(
|
for pri in range(5):
|
||||||
"update cards set priority = :pri %s where id = :id" % extra,
|
cs = [c[0] for c in cards if c[1] == pri]
|
||||||
[{'id': c[0], 'pri': c[1], 'm': time.time()} for c in cards])
|
if cs:
|
||||||
|
self.s.statement((
|
||||||
|
"update cards set priority = :pri %s where id in %s "
|
||||||
|
"and priority != :pri") % (
|
||||||
|
extra, ids2str(cs)), pri=pri, m=time.time())
|
||||||
cnt = self.s.execute(
|
cnt = self.s.execute(
|
||||||
"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").rowcount
|
"priority = 0 and isDue = 1").rowcount
|
||||||
|
|
Loading…
Reference in a new issue