Stop metadata backup thread before bulk metadata edits to improve performance

This commit is contained in:
Kovid Goyal 2010-09-28 16:55:22 -06:00
parent d45ee9ed9b
commit 96bc9f6bec
4 changed files with 34 additions and 20 deletions

View File

@ -184,7 +184,7 @@ class EditMetadataAction(InterfaceAction):
self.gui.tags_view.blockSignals(True)
try:
changed = MetadataBulkDialog(self.gui, rows,
self.gui.library_view.model().db).changed
self.gui.library_view.model()).changed
finally:
self.gui.tags_view.blockSignals(False)
if changed:

View File

@ -142,12 +142,13 @@ class MetadataBulkDialog(QDialog, Ui_MetadataBulkDialog):
_('Append to field'),
]
def __init__(self, window, rows, db):
def __init__(self, window, rows, model):
QDialog.__init__(self, window)
Ui_MetadataBulkDialog.__init__(self)
self.setupUi(self)
self.db = db
self.ids = [db.id(r) for r in rows]
self.model = model
self.db = model.db
self.ids = [self.db.id(r) for r in rows]
self.box_title.setText('<p>' +
_('Editing meta information for <b>%d books</b>') %
len(rows))
@ -170,7 +171,7 @@ class MetadataBulkDialog(QDialog, Ui_MetadataBulkDialog):
self.tag_editor_button.clicked.connect(self.tag_editor)
self.autonumber_series.stateChanged[int].connect(self.auto_number_changed)
if len(db.custom_field_keys(include_composites=False)) == 0:
if len(self.db.custom_field_keys(include_composites=False)) == 0:
self.central_widget.removeTab(1)
else:
self.create_custom_column_editors()
@ -617,8 +618,15 @@ class MetadataBulkDialog(QDialog, Ui_MetadataBulkDialog):
self.worker = Worker(args, self.db, self.ids,
getattr(self, 'custom_column_widgets', []),
Dispatcher(bb.accept, parent=bb))
self.worker.start()
bb.exec_()
# The metadata backup thread causes database commits
# which can slow down bulk editing of large numbers of books
self.model.stop_metadata_backup()
try:
self.worker.start()
bb.exec_()
finally:
self.model.start_metadata_backup()
if self.worker.error is not None:
return error_dialog(self, _('Failed'),

View File

@ -159,17 +159,24 @@ class BooksModel(QAbstractTableModel): # {{{
# do something on the GUI thread. Deadlock.
self.cover_cache = CoverCache(db, FunctionDispatcher(self.db.cover))
self.cover_cache.start()
if self.metadata_backup is not None:
self.metadata_backup.stop()
# Would like to to a join here, but the thread might be waiting to
# do something on the GUI thread. Deadlock.
self.metadata_backup = MetadataBackup(db)
self.metadata_backup.start()
self.stop_metadata_backup()
self.start_metadata_backup()
def refresh_cover(event, ids):
if event == 'cover' and self.cover_cache is not None:
self.cover_cache.refresh(ids)
db.add_listener(refresh_cover)
def start_metadata_backup(self):
self.metadata_backup = MetadataBackup(self.db)
self.metadata_backup.start()
def stop_metadata_backup(self):
if getattr(self, 'metadata_backup', None) is not None:
self.metadata_backup.stop()
# Would like to to a join here, but the thread might be waiting to
# do something on the GUI thread. Deadlock.
def refresh_ids(self, ids, current_row=-1):
rows = self.db.refresh_ids(ids)
if rows:

View File

@ -106,14 +106,13 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
d.exec_()
def compact(self, *args):
from calibre.library.caches import MetadataBackup
m = self.gui.library_view.model()
if m.metadata_backup is not None:
m.metadata_backup.stop()
d = CheckIntegrity(m.db, self)
d.exec_()
m.metadata_backup = MetadataBackup(m.db)
m.metadata_backup.start()
m.stop_metadata_backup()
try:
d = CheckIntegrity(m.db, self)
d.exec_()
finally:
m.start_metadata_backup()
def open_config_dir(self, *args):
from calibre.utils.config import config_dir