add a temporary cache to bring deck list performance back

This commit is contained in:
Damien Elmes 2020-03-30 20:23:40 +10:00
parent 35c03af520
commit fa2965d39a
2 changed files with 15 additions and 1 deletions

View file

@ -102,6 +102,7 @@ class DeckManager:
def __init__(self, col: anki.storage._Collection) -> None: def __init__(self, col: anki.storage._Collection) -> None:
self.col = col.weakref() self.col = col.weakref()
self.decks = {} self.decks = {}
self._dconf_cache: Optional[Dict[int, Dict[str, Any]]] = None
def load(self, decks: str, dconf: str) -> None: def load(self, decks: str, dconf: str) -> None:
self.decks = json.loads(decks) self.decks = json.loads(decks)
@ -371,6 +372,8 @@ class DeckManager:
return deck return deck
def getConf(self, confId: int) -> Any: def getConf(self, confId: int) -> Any:
if self._dconf_cache is not None:
return self._dconf_cache.get(confId)
return self.col.backend.get_deck_config(confId) return self.col.backend.get_deck_config(confId)
def updateConf(self, g: Dict[str, Any]) -> None: def updateConf(self, g: Dict[str, Any]) -> None:
@ -420,6 +423,13 @@ class DeckManager:
if not oldOrder: if not oldOrder:
self.col.sched.resortConf(new) self.col.sched.resortConf(new)
# temporary caching - don't use this as it will be removed
def _enable_dconf_cache(self):
self._dconf_cache = {c["id"]: c for c in self.allConf()}
def _disable_dconf_cache(self):
self._dconf_cache = None
# Deck utils # Deck utils
############################################################# #############################################################

View file

@ -270,7 +270,11 @@ order by due"""
return data return data
def deckDueTree(self) -> Any: def deckDueTree(self) -> Any:
return self._groupChildren(self.deckDueList()) self.col.decks._enable_dconf_cache()
try:
return self._groupChildren(self.deckDueList())
finally:
self.col.decks._disable_dconf_cache()
def _groupChildren(self, grps: List[List[Any]]) -> Any: def _groupChildren(self, grps: List[List[Any]]) -> Any:
# first, split the group names into components # first, split the group names into components