Check library: Fix popup about check being performed not being rendered

The vacuum locks the db and there are various events on the GUI thread
that can cause db access which causes the GUI thread to hang. Find and
fix the most common of these. It isnt a complete solution, but its
better than nothing.
This commit is contained in:
Kovid Goyal 2022-07-30 00:05:32 +05:30
parent 1b1715b8fe
commit 96d9f39ad0
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 14 additions and 3 deletions

View File

@ -142,6 +142,7 @@ class Cache:
def __init__(self, backend, library_database_instance=None): def __init__(self, backend, library_database_instance=None):
self.shutting_down = False self.shutting_down = False
self.is_doing_rebuild_or_vacuum = False
self.backend = backend self.backend = backend
self.library_database_instance = (None if library_database_instance is None else self.library_database_instance = (None if library_database_instance is None else
weakref.ref(library_database_instance)) weakref.ref(library_database_instance))
@ -2429,7 +2430,11 @@ class Cache:
@write_api @write_api
def vacuum(self): def vacuum(self):
self.backend.vacuum() self.is_doing_rebuild_or_vacuum = True
try:
self.backend.vacuum()
finally:
self.is_doing_rebuild_or_vacuum = False
def __del__(self): def __del__(self):
self.close() self.close()

View File

@ -659,7 +659,9 @@ class ChooseLibraryAction(InterfaceAction):
d = DBCheck(self.gui, db) d = DBCheck(self.gui, db)
try: try:
d.start() d.start()
d.exec() from calibre.gui2.widgets import BusyCursor
with BusyCursor():
d.exec()
try: try:
m.close() m.close()
except Exception: except Exception:

View File

@ -612,7 +612,9 @@ class Scheduler(QObject):
from calibre.gui2.ui import get_gui from calibre.gui2.ui import get_gui
gui = get_gui() gui = get_gui()
if gui is not None: if gui is not None:
return gui.current_db ans = gui.current_db
if not ans.new_api.is_doing_rebuild_or_vacuum:
return ans
def oldest_check(self): def oldest_check(self):
if self.oldest > 0: if self.oldest > 0:

View File

@ -966,6 +966,8 @@ class BooksModel(QAbstractTableModel): # {{{
self.column_to_dc_decorator_map = [self.dc_decorator.get(col, None) for col in self.column_map] self.column_to_dc_decorator_map = [self.dc_decorator.get(col, None) for col in self.column_map]
def data(self, index, role): def data(self, index, role):
if self.db.new_api.is_doing_rebuild_or_vacuum:
return None
col = index.column() col = index.column()
# in obscure cases where custom columns are both edited and added, for a time # in obscure cases where custom columns are both edited and added, for a time
# the column map does not accurately represent the screen. In these cases, # the column map does not accurately represent the screen. In these cases,