cache deck name->obj map to improve many decks case

This commit is contained in:
Damien Elmes 2018-05-29 19:26:37 +10:00
parent e93dedc7c6
commit 9c7c52b99c
3 changed files with 13 additions and 4 deletions

View file

@ -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
########################################################################## ##########################################################################

View file

@ -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:

View file

@ -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: