From ab6eeb5882b6cd740329fef61035359ca768f13d Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Fri, 3 Apr 2020 09:54:01 +1000 Subject: [PATCH] ensure pending deck/tag/note type changes flushed before searching --- pylib/anki/collection.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/pylib/anki/collection.py b/pylib/anki/collection.py index 026ccb886..e8a3b93fa 100644 --- a/pylib/anki/collection.py +++ b/pylib/anki/collection.py @@ -216,17 +216,20 @@ crt=?, mod=?, scm=?, dty=?, usn=?, ls=?, conf=?""", json.dumps(self.conf), ) + def flush_all_changes(self, mod: Optional[int] = None): + self.models.flush() + self.decks.flush() + self.tags.flush() + if self.db.mod: + self.flush(mod) + def save( self, name: Optional[str] = None, mod: Optional[int] = None, trx: bool = True ) -> None: "Flush, commit DB, and take out another write lock if trx=True." - # let the managers conditionally flush - self.models.flush() - self.decks.flush() - self.tags.flush() + self.flush_all_changes(mod) # and flush deck + bump mod if db has been changed if self.db.mod: - self.flush(mod=mod) self.db.commit() self.db.mod = False if trx: @@ -630,9 +633,11 @@ where c.nid = n.id and c.id in %s group by nid""" def find_cards( self, query: str, order: Union[bool, str, int] = False, reverse: bool = False, ) -> Sequence[int]: + self.flush_all_changes() return self.backend.search_cards(query, order, reverse) def find_notes(self, query: str) -> Sequence[int]: + self.flush_all_changes() return self.backend.search_notes(query) def findReplace(