mirror of
https://github.com/ankitects/anki.git
synced 2025-09-21 15:32: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']))
|
actv.append((g['name'], g['id']))
|
||||||
return actv
|
return actv
|
||||||
|
|
||||||
def parents(self, did):
|
def parents(self, did, nameMap=None):
|
||||||
"All parents of did."
|
"All parents of did."
|
||||||
# get parent and grandparent names
|
# get parent and grandparent names
|
||||||
parents = []
|
parents = []
|
||||||
|
@ -484,7 +484,11 @@ class DeckManager:
|
||||||
parents.append(parents[-1] + "::" + part)
|
parents.append(parents[-1] + "::" + part)
|
||||||
# convert to objects
|
# convert to objects
|
||||||
for c, p in enumerate(parents):
|
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
|
return parents
|
||||||
|
|
||||||
def parentsByName(self, name):
|
def parentsByName(self, name):
|
||||||
|
@ -503,6 +507,9 @@ class DeckManager:
|
||||||
|
|
||||||
return parents
|
return parents
|
||||||
|
|
||||||
|
def nameMap(self):
|
||||||
|
return dict((d['name'], d) for d in self.decks.values())
|
||||||
|
|
||||||
# Sync handling
|
# Sync handling
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
|
|
|
@ -183,6 +183,7 @@ order by due""" % self._deckLimit(),
|
||||||
tot = 0
|
tot = 0
|
||||||
pcounts = {}
|
pcounts = {}
|
||||||
# for each of the active decks
|
# for each of the active decks
|
||||||
|
nameMap = self.col.decks.nameMap()
|
||||||
for did in self.col.decks.active():
|
for did in self.col.decks.active():
|
||||||
# early alphas were setting the active ids as a str
|
# early alphas were setting the active ids as a str
|
||||||
did = int(did)
|
did = int(did)
|
||||||
|
@ -191,7 +192,7 @@ order by due""" % self._deckLimit(),
|
||||||
if not lim:
|
if not lim:
|
||||||
continue
|
continue
|
||||||
# check the parents
|
# check the parents
|
||||||
parents = self.col.decks.parents(did)
|
parents = self.col.decks.parents(did, nameMap)
|
||||||
for p in parents:
|
for p in parents:
|
||||||
# add if missing
|
# add if missing
|
||||||
if p['id'] not in pcounts:
|
if p['id'] not in pcounts:
|
||||||
|
|
|
@ -171,6 +171,7 @@ order by due""" % self._deckLimit(),
|
||||||
tot = 0
|
tot = 0
|
||||||
pcounts = {}
|
pcounts = {}
|
||||||
# for each of the active decks
|
# for each of the active decks
|
||||||
|
nameMap = self.col.decks.nameMap()
|
||||||
for did in self.col.decks.active():
|
for did in self.col.decks.active():
|
||||||
# early alphas were setting the active ids as a str
|
# early alphas were setting the active ids as a str
|
||||||
did = int(did)
|
did = int(did)
|
||||||
|
@ -179,7 +180,7 @@ order by due""" % self._deckLimit(),
|
||||||
if not lim:
|
if not lim:
|
||||||
continue
|
continue
|
||||||
# check the parents
|
# check the parents
|
||||||
parents = self.col.decks.parents(did)
|
parents = self.col.decks.parents(did, nameMap)
|
||||||
for p in parents:
|
for p in parents:
|
||||||
# add if missing
|
# add if missing
|
||||||
if p['id'] not in pcounts:
|
if p['id'] not in pcounts:
|
||||||
|
|
Loading…
Reference in a new issue