mirror of
https://github.com/ankitects/anki.git
synced 2025-09-20 06:52:21 -04:00
run Check DB in a background thread
Since the DB is now stored behind a mutex, we're no longer limited to accessing the database on the main thread.
This commit is contained in:
parent
daaf8bdc70
commit
32555b2857
1 changed files with 23 additions and 18 deletions
|
@ -12,6 +12,7 @@ import signal
|
||||||
import time
|
import time
|
||||||
import zipfile
|
import zipfile
|
||||||
from argparse import Namespace
|
from argparse import Namespace
|
||||||
|
from concurrent.futures import Future
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple
|
from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple
|
||||||
|
|
||||||
|
@ -1260,25 +1261,29 @@ will be lost. Continue?"""
|
||||||
|
|
||||||
def onCheckDB(self):
|
def onCheckDB(self):
|
||||||
"True if no problems"
|
"True if no problems"
|
||||||
self.progress.start(immediate=True)
|
self.progress.start()
|
||||||
ret, ok = self.col.fixIntegrity()
|
|
||||||
self.progress.finish()
|
|
||||||
if not ok:
|
|
||||||
showText(ret)
|
|
||||||
else:
|
|
||||||
tooltip(ret)
|
|
||||||
|
|
||||||
# if an error has directed the user to check the database,
|
def onDone(future: Future):
|
||||||
# silently clean up any broken reset hooks which distract from
|
self.progress.finish()
|
||||||
# the underlying issue
|
ret, ok = future.result()
|
||||||
while True:
|
|
||||||
try:
|
if not ok:
|
||||||
self.reset()
|
showText(ret)
|
||||||
break
|
else:
|
||||||
except Exception as e:
|
tooltip(ret)
|
||||||
print("swallowed exception in reset hook:", e)
|
|
||||||
continue
|
# if an error has directed the user to check the database,
|
||||||
return ret
|
# silently clean up any broken reset hooks which distract from
|
||||||
|
# the underlying issue
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
self.reset()
|
||||||
|
break
|
||||||
|
except Exception as e:
|
||||||
|
print("swallowed exception in reset hook:", e)
|
||||||
|
continue
|
||||||
|
|
||||||
|
self.taskman.run_in_background(self.col.fixIntegrity, onDone)
|
||||||
|
|
||||||
def on_check_media_db(self) -> None:
|
def on_check_media_db(self) -> None:
|
||||||
check_media_db(self)
|
check_media_db(self)
|
||||||
|
|
Loading…
Reference in a new issue