drop usage of nameMap in deckbrowser

It was unnecessary, and being called multiple times as we recursed
downwards, slowing things down.
This commit is contained in:
Damien Elmes 2020-05-16 10:02:08 +10:00
parent 83adfb60cf
commit 75d3eebafe

View File

@ -157,28 +157,20 @@ where id > ?""",
buf += self._topLevelDragRow() buf += self._topLevelDragRow()
else: else:
buf = "" buf = ""
nameMap = self.mw.col.decks.nameMap()
for node in nodes: for node in nodes:
buf += self._deckRow(node, depth, len(nodes), nameMap) buf += self._deckRow(node, depth)
if depth == 0: if depth == 0:
buf += self._topLevelDragRow() buf += self._topLevelDragRow()
return buf return buf
def _deckRow(self, node, depth, cnt, nameMap): def _deckRow(self, node, depth):
name, did, due, lrn, new, children = node name, did, due, lrn, new, children = node
deck = self.mw.col.decks.get(did) deck = self.mw.col.decks.get(did)
if did == 1 and cnt > 1 and not children: collapsed = self.mw.col.decks.get(did)["collapsed"]
# if the default deck is empty, hide it if collapsed:
if not self.mw.col.db.scalar("select 1 from cards where did = 1"):
return ""
# parent toggled for collapsing
for parent in self.mw.col.decks.parents(did, nameMap):
if parent["collapsed"]:
buff = ""
return buff
prefix = "-"
if self.mw.col.decks.get(did)["collapsed"]:
prefix = "+" prefix = "+"
else:
prefix = "-"
due += lrn due += lrn
def indent(): def indent():
@ -227,6 +219,7 @@ where id > ?""",
"<img src='/_anki/imgs/gears.svg' class=gears></a></td></tr>" % did "<img src='/_anki/imgs/gears.svg' class=gears></a></td></tr>" % did
) )
# children # children
if not collapsed:
buf += self._renderDeckTree(children, depth + 1) buf += self._renderDeckTree(children, depth + 1)
return buf return buf