diff --git a/src/calibre/db/backend.py b/src/calibre/db/backend.py index b75ab5c45b..67ccd8c8ec 100644 --- a/src/calibre/db/backend.py +++ b/src/calibre/db/backend.py @@ -2655,4 +2655,16 @@ class DB: def backup_notes_database(self, path): self._backup_database(path, 'notes_db') + + def size_stats(self): + main_size = notes_size = fts_size = 0 + with suppress(OSError): + main_size = os.path.getsize(self.dbpath) + if self.conn.notes_dbpath: + with suppress(OSError): + notes_size = os.path.getsize(self.conn.notes_dbpath) + if self.conn.fts_dbpath: + with suppress(OSError): + fts_size = os.path.getsize(self.conn.fts_dbpath) + return {'main': main_size, 'fts': fts_size, 'notes': notes_size} # }}} diff --git a/src/calibre/db/cache.py b/src/calibre/db/cache.py index a9cd3abebd..b7881d0ce0 100644 --- a/src/calibre/db/cache.py +++ b/src/calibre/db/cache.py @@ -1405,6 +1405,10 @@ class Cache: ids_to_sort.sort(reverse=True) return ids_to_sort[:count] + @read_api + def size_stats(self) -> dict[str, int]: + return self.backend.size_stats() + @read_api def multisort(self, fields, ids_to_sort=None, virtual_fields=None): ''' diff --git a/src/calibre/gui2/actions/choose_library.py b/src/calibre/gui2/actions/choose_library.py index 087e5f5d4a..ec9dd9db48 100644 --- a/src/calibre/gui2/actions/choose_library.py +++ b/src/calibre/gui2/actions/choose_library.py @@ -678,6 +678,7 @@ class ChooseLibraryAction(InterfaceAction): db = m.db db.prefs.disable_setting = True library_path = db.library_path + before = db.new_api.size_stats() d = DBCheck(self.gui, db) try: @@ -692,10 +693,22 @@ class ChooseLibraryAction(InterfaceAction): if d.rejected: return if d.error is None: + after = self.gui.current_db.new_api.size_stats() + det_msg = '' + from calibre import human_readable + for which, title in {'main': _('books'), 'fts': _('full text search'), 'notes': _('notes')}.items(): + if which != 'main' and not getattr(d, which).isChecked(): + continue + det_msg += '\n' + if before[which] == after[which]: + det_msg += _('Size of the {} database was unchanged.').format(title) + else: + det_msg += _('Size of the {0} database reduced from {1} to {2}.').format( + title, human_readable(before[which]), human_readable(after[which])) if not question_dialog(self.gui, _('Success'), _('Found no errors in your calibre library database.' ' Do you want calibre to check if the files in your' - ' library match the information in the database?')): + ' library match the information in the database?'), det_msg=det_msg.strip()): return else: return error_dialog(self.gui, _('Failed'),