ensure pending deck/tag/note type changes flushed before searching

This commit is contained in:
Damien Elmes 2020-04-03 09:54:01 +10:00
parent 2c99a4203f
commit ab6eeb5882

View File

@ -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(