From 96d9f39ad082056ac35de521d92a74e658e8d141 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 30 Jul 2022 00:05:32 +0530 Subject: [PATCH] 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. --- src/calibre/db/cache.py | 7 ++++++- src/calibre/gui2/actions/choose_library.py | 4 +++- src/calibre/gui2/dialogs/scheduler.py | 4 +++- src/calibre/gui2/library/models.py | 2 ++ 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/calibre/db/cache.py b/src/calibre/db/cache.py index 96f01d483b..0f9c332eda 100644 --- a/src/calibre/db/cache.py +++ b/src/calibre/db/cache.py @@ -142,6 +142,7 @@ class Cache: def __init__(self, backend, library_database_instance=None): self.shutting_down = False + self.is_doing_rebuild_or_vacuum = False self.backend = backend self.library_database_instance = (None if library_database_instance is None else weakref.ref(library_database_instance)) @@ -2429,7 +2430,11 @@ class Cache: @write_api 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): self.close() diff --git a/src/calibre/gui2/actions/choose_library.py b/src/calibre/gui2/actions/choose_library.py index 2b8396390e..b6cf8903a5 100644 --- a/src/calibre/gui2/actions/choose_library.py +++ b/src/calibre/gui2/actions/choose_library.py @@ -659,7 +659,9 @@ class ChooseLibraryAction(InterfaceAction): d = DBCheck(self.gui, db) try: d.start() - d.exec() + from calibre.gui2.widgets import BusyCursor + with BusyCursor(): + d.exec() try: m.close() except Exception: diff --git a/src/calibre/gui2/dialogs/scheduler.py b/src/calibre/gui2/dialogs/scheduler.py index 7a06c1d49f..c133d872ae 100644 --- a/src/calibre/gui2/dialogs/scheduler.py +++ b/src/calibre/gui2/dialogs/scheduler.py @@ -612,7 +612,9 @@ class Scheduler(QObject): from calibre.gui2.ui import get_gui gui = get_gui() 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): if self.oldest > 0: diff --git a/src/calibre/gui2/library/models.py b/src/calibre/gui2/library/models.py index 75d764ec4a..dacfcd98b5 100644 --- a/src/calibre/gui2/library/models.py +++ b/src/calibre/gui2/library/models.py @@ -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] def data(self, index, role): + if self.db.new_api.is_doing_rebuild_or_vacuum: + return None col = index.column() # 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,