mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix #2058115 [[Enhancement] Report compacted database size during Check Library](https://bugs.launchpad.net/calibre/+bug/2058115)
This commit is contained in:
parent
c4df98f9af
commit
461a5ea571
@ -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}
|
||||
# }}}
|
||||
|
@ -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):
|
||||
'''
|
||||
|
@ -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'),
|
||||
|
Loading…
x
Reference in New Issue
Block a user