Fix #2058115 [[Enhancement] Report compacted database size during Check Library](https://bugs.launchpad.net/calibre/+bug/2058115)

This commit is contained in:
Kovid Goyal 2024-03-31 18:03:37 +05:30
parent c4df98f9af
commit 461a5ea571
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 30 additions and 1 deletions

View File

@ -2655,4 +2655,16 @@ class DB:
def backup_notes_database(self, path): def backup_notes_database(self, path):
self._backup_database(path, 'notes_db') 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}
# }}} # }}}

View File

@ -1405,6 +1405,10 @@ class Cache:
ids_to_sort.sort(reverse=True) ids_to_sort.sort(reverse=True)
return ids_to_sort[:count] return ids_to_sort[:count]
@read_api
def size_stats(self) -> dict[str, int]:
return self.backend.size_stats()
@read_api @read_api
def multisort(self, fields, ids_to_sort=None, virtual_fields=None): def multisort(self, fields, ids_to_sort=None, virtual_fields=None):
''' '''

View File

@ -678,6 +678,7 @@ class ChooseLibraryAction(InterfaceAction):
db = m.db db = m.db
db.prefs.disable_setting = True db.prefs.disable_setting = True
library_path = db.library_path library_path = db.library_path
before = db.new_api.size_stats()
d = DBCheck(self.gui, db) d = DBCheck(self.gui, db)
try: try:
@ -692,10 +693,22 @@ class ChooseLibraryAction(InterfaceAction):
if d.rejected: if d.rejected:
return return
if d.error is None: 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'), if not question_dialog(self.gui, _('Success'),
_('Found no errors in your calibre library database.' _('Found no errors in your calibre library database.'
' Do you want calibre to check if the files in your' ' 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 return
else: else:
return error_dialog(self.gui, _('Failed'), return error_dialog(self.gui, _('Failed'),