only update active when selecting deck/resetting

We were previously doing this every time a card was answered.
This commit is contained in:
Damien Elmes 2020-05-16 14:18:45 +10:00
parent f747063752
commit 1cddd6d23e
3 changed files with 6 additions and 15 deletions

View File

@ -104,9 +104,6 @@ class DeckManager:
deck["name"] = name
self.update(deck)
# fixme
self.maybeAddToActive()
# fixme
hooks.deck_added(deck)
@ -248,12 +245,6 @@ class DeckManager:
except anki.rsbackend.ExistsError:
raise DeckRenameError("deck already exists")
# self.decks[str(g["id"])] = g
self.maybeAddToActive()
# mark registry changed, but don't bump mod time
# self.save()
def rename(self, g: Dict[str, Any], newName: str) -> None:
"Rename deck prefix to NAME if not exists. Updates children."
g["name"] = newName
@ -262,7 +253,6 @@ class DeckManager:
# fixme: ensure rename of b in a::b::c generates new b
# fixme: renaming may have altered active did order
# self.maybeAddToActive()
def renameForDragAndDrop(self, draggedDeckDid: int, ontoDeckDid: Any) -> None:
draggedDeck = self.get(draggedDeckDid)
@ -452,11 +442,6 @@ class DeckManager:
intTime(),
)
def maybeAddToActive(self) -> None:
# reselect current deck, or default if current has disappeared
c = self.current()
self.select(c["id"])
def cids(self, did: int, children: bool = False) -> Any:
if not children:
return self.col.db.list("select id from cards where did=?", did)
@ -494,6 +479,10 @@ class DeckManager:
self.col.conf["activeDecks"] = [did] + [a[1] for a in actv]
self.col.setMod()
# don't use this, it will likely go away
def update_active(self):
self.select(self.current()["id"])
def children(self, did: int) -> List[Tuple[Any, Any]]:
"All children of did, as (name, id)."
name = self.get(did)["name"]

View File

@ -60,6 +60,7 @@ class Scheduler:
return None
def reset(self) -> None:
self.col.decks.update_active()
self._updateCutoff()
self._resetLrn()
self._resetRev()

View File

@ -25,6 +25,7 @@ def test_basic():
assert deck.decks.active() == [parentId]
# let's create a child
childId = deck.decks.id("new deck::child")
deck.sched.reset()
# it should have been added to the active list
assert deck.decks.selected() == parentId
assert deck.decks.active() == [parentId, childId]