mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 08:46:37 -04:00
add a temporary cache to bring deck list performance back
This commit is contained in:
parent
35c03af520
commit
fa2965d39a
2 changed files with 15 additions and 1 deletions
|
@ -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
|
||||
#############################################################
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue