From fa2965d39a962de448f364ac3c07161c0ff64f53 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Mon, 30 Mar 2020 20:23:40 +1000 Subject: [PATCH] add a temporary cache to bring deck list performance back --- pylib/anki/decks.py | 10 ++++++++++ pylib/anki/schedv2.py | 6 +++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/pylib/anki/decks.py b/pylib/anki/decks.py index e86b69725..c2f16ad49 100644 --- a/pylib/anki/decks.py +++ b/pylib/anki/decks.py @@ -102,6 +102,7 @@ class DeckManager: def __init__(self, col: anki.storage._Collection) -> None: self.col = col.weakref() self.decks = {} + self._dconf_cache: Optional[Dict[int, Dict[str, Any]]] = None def load(self, decks: str, dconf: str) -> None: self.decks = json.loads(decks) @@ -371,6 +372,8 @@ class DeckManager: return deck 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) def updateConf(self, g: Dict[str, Any]) -> None: @@ -420,6 +423,13 @@ class DeckManager: if not oldOrder: 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 ############################################################# diff --git a/pylib/anki/schedv2.py b/pylib/anki/schedv2.py index 07466ffd3..75ab8b5d0 100644 --- a/pylib/anki/schedv2.py +++ b/pylib/anki/schedv2.py @@ -270,7 +270,11 @@ order by due""" return data 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: # first, split the group names into components