mirror of
https://github.com/ankitects/anki.git
synced 2025-09-21 07:22:23 -04:00
cache deck name->obj map to improve many decks case
This commit is contained in:
parent
e93dedc7c6
commit
9c7c52b99c
3 changed files with 13 additions and 4 deletions
|
@ -473,7 +473,7 @@ class DeckManager:
|
|||
actv.append((g['name'], g['id']))
|
||||
return actv
|
||||
|
||||
def parents(self, did):
|
||||
def parents(self, did, nameMap=None):
|
||||
"All parents of did."
|
||||
# get parent and grandparent names
|
||||
parents = []
|
||||
|
@ -484,7 +484,11 @@ class DeckManager:
|
|||
parents.append(parents[-1] + "::" + part)
|
||||
# convert to objects
|
||||
for c, p in enumerate(parents):
|
||||
parents[c] = self.get(self.id(p))
|
||||
if nameMap:
|
||||
deck = nameMap[p]
|
||||
else:
|
||||
deck = self.get(self.id(p))
|
||||
parents[c] = deck
|
||||
return parents
|
||||
|
||||
def parentsByName(self, name):
|
||||
|
@ -503,6 +507,9 @@ class DeckManager:
|
|||
|
||||
return parents
|
||||
|
||||
def nameMap(self):
|
||||
return dict((d['name'], d) for d in self.decks.values())
|
||||
|
||||
# Sync handling
|
||||
##########################################################################
|
||||
|
||||
|
|
|
@ -183,6 +183,7 @@ order by due""" % self._deckLimit(),
|
|||
tot = 0
|
||||
pcounts = {}
|
||||
# for each of the active decks
|
||||
nameMap = self.col.decks.nameMap()
|
||||
for did in self.col.decks.active():
|
||||
# early alphas were setting the active ids as a str
|
||||
did = int(did)
|
||||
|
@ -191,7 +192,7 @@ order by due""" % self._deckLimit(),
|
|||
if not lim:
|
||||
continue
|
||||
# check the parents
|
||||
parents = self.col.decks.parents(did)
|
||||
parents = self.col.decks.parents(did, nameMap)
|
||||
for p in parents:
|
||||
# add if missing
|
||||
if p['id'] not in pcounts:
|
||||
|
|
|
@ -171,6 +171,7 @@ order by due""" % self._deckLimit(),
|
|||
tot = 0
|
||||
pcounts = {}
|
||||
# for each of the active decks
|
||||
nameMap = self.col.decks.nameMap()
|
||||
for did in self.col.decks.active():
|
||||
# early alphas were setting the active ids as a str
|
||||
did = int(did)
|
||||
|
@ -179,7 +180,7 @@ order by due""" % self._deckLimit(),
|
|||
if not lim:
|
||||
continue
|
||||
# check the parents
|
||||
parents = self.col.decks.parents(did)
|
||||
parents = self.col.decks.parents(did, nameMap)
|
||||
for p in parents:
|
||||
# add if missing
|
||||
if p['id'] not in pcounts:
|
||||
|
|
Loading…
Reference in a new issue