From 62eca8531635fd4ad25708d8039b8a8cbf4d53c0 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Wed, 18 Aug 2010 21:30:56 +0100 Subject: [PATCH 1/3] Make metadata single use fewer transactions --- src/calibre/gui2/custom_column_widgets.py | 4 +-- src/calibre/gui2/dialogs/metadata_single.py | 38 +++++++++++++-------- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/src/calibre/gui2/custom_column_widgets.py b/src/calibre/gui2/custom_column_widgets.py index 4a1a85f159..f6ed1e4d6f 100644 --- a/src/calibre/gui2/custom_column_widgets.py +++ b/src/calibre/gui2/custom_column_widgets.py @@ -41,7 +41,7 @@ class Base(object): val = self.gui_val val = self.normalize_ui_val(val) if val != self.initial_val: - self.db.set_custom(book_id, val, num=self.col_id, notify=notify) + self.db._set_custom(book_id, val, num=self.col_id, notify=notify) def normalize_db_val(self, val): return val @@ -304,7 +304,7 @@ class Series(Base): num=self.col_id) else: s_index = None - self.db.set_custom(book_id, val, extra=s_index, + self.db._set_custom(book_id, val, extra=s_index, num=self.col_id, notify=notify) widgets = { diff --git a/src/calibre/gui2/dialogs/metadata_single.py b/src/calibre/gui2/dialogs/metadata_single.py index 50223923c1..9780f84c61 100644 --- a/src/calibre/gui2/dialogs/metadata_single.py +++ b/src/calibre/gui2/dialogs/metadata_single.py @@ -668,9 +668,9 @@ class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog): self.tags.setText(', '.join(book.tags)) if book.series is not None: if self.series.text() is None or self.series.text() == '': - self.series.setText(book.series) - if book.series_index is not None: - self.series_index.setValue(book.series_index) + self.series.setText(book.series) + if book.series_index is not None: + self.series_index.setValue(book.series_index) else: error_dialog(self, _('Cannot fetch metadata'), _('You must specify at least one of ISBN, Title, ' @@ -719,24 +719,31 @@ class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog): self.db.set_authors(self.id, string_to_authors(au), notify=False) aus = unicode(self.author_sort.text()) if aus: - self.db.set_author_sort(self.id, aus, notify=False) + self.db.set_author_sort(self.id, aus, notify=False, commit=False) self.db.set_isbn(self.id, - re.sub(r'[^0-9a-zA-Z]', '', unicode(self.isbn.text())), notify=False) - self.db.set_rating(self.id, 2*self.rating.value(), notify=False) - self.db.set_publisher(self.id, unicode(self.publisher.currentText()), notify=False) + re.sub(r'[^0-9a-zA-Z]', '', unicode(self.isbn.text())), + notify=False, commit=False) + self.db.set_rating(self.id, 2*self.rating.value(), notify=False, + commit=False) + self.db.set_publisher(self.id, unicode(self.publisher.currentText()), + notify=False, commit=False) self.db.set_tags(self.id, [x.strip() for x in - unicode(self.tags.text()).split(',')], notify=False) + unicode(self.tags.text()).split(',')], notify=False, commit=False) self.db.set_series(self.id, - unicode(self.series.currentText()).strip(), notify=False) - self.db.set_series_index(self.id, self.series_index.value(), notify=False) - self.db.set_comment(self.id, unicode(self.comments.toPlainText()), notify=False) + unicode(self.series.currentText()).strip(), notify=False, + commit=False) + self.db.set_series_index(self.id, self.series_index.value(), + notify=False, commit=False) + self.db.set_comment(self.id, unicode(self.comments.toPlainText()), + notify=False, commit=False) d = self.pubdate.date() d = qt_to_dt(d) - self.db.set_pubdate(self.id, d, notify=False) + self.db.set_pubdate(self.id, d, notify=False, commit=False) d = self.date.date() d = qt_to_dt(d) if d.date() != self.orig_timestamp.date(): - self.db.set_timestamp(self.id, d, notify=False) + self.db.set_timestamp(self.id, d, notify=False, commit=False) + self.db.conn.commit() if self.cover_changed: if self.cover_data is not None: @@ -745,6 +752,7 @@ class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog): self.db.remove_cover(self.id) for w in getattr(self, 'custom_column_widgets', []): w.commit(self.id) + self.db.conn.commit() except IOError, err: if err.errno == 13: # Permission denied fname = err.filename if err.filename else 'file' @@ -769,9 +777,9 @@ class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog): wg = dynamic.get('metasingle_window_geometry', None) ss = dynamic.get('metasingle_splitter_state', None) if wg is not None: - self.restoreGeometry(wg) + self.restoreGeometry(wg) if ss is not None: - self.splitter.restoreState(ss) + self.splitter.restoreState(ss) def save_state(self): dynamic.set('metasingle_window_geometry', bytes(self.saveGeometry())) From c334e84b48a67586edcb22893335b35fe5dd913d Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Wed, 18 Aug 2010 21:35:08 +0100 Subject: [PATCH 2/3] Change metadata single to use db.commit instead of conn.commit --- src/calibre/gui2/dialogs/metadata_single.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/calibre/gui2/dialogs/metadata_single.py b/src/calibre/gui2/dialogs/metadata_single.py index 9780f84c61..3e07422967 100644 --- a/src/calibre/gui2/dialogs/metadata_single.py +++ b/src/calibre/gui2/dialogs/metadata_single.py @@ -743,7 +743,7 @@ class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog): d = qt_to_dt(d) if d.date() != self.orig_timestamp.date(): self.db.set_timestamp(self.id, d, notify=False, commit=False) - self.db.conn.commit() + self.db.commit() if self.cover_changed: if self.cover_data is not None: @@ -752,7 +752,7 @@ class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog): self.db.remove_cover(self.id) for w in getattr(self, 'custom_column_widgets', []): w.commit(self.id) - self.db.conn.commit() + self.db.commit() except IOError, err: if err.errno == 13: # Permission denied fname = err.filename if err.filename else 'file' From c29ee263e0f41dc4a4f6cbe6a1e526a6d0b0b95f Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Wed, 18 Aug 2010 21:38:22 +0100 Subject: [PATCH 3/3] Add commit= parameter to set custom. Use it in cc_widgets --- src/calibre/gui2/custom_column_widgets.py | 7 ++++--- src/calibre/library/custom_columns.py | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/calibre/gui2/custom_column_widgets.py b/src/calibre/gui2/custom_column_widgets.py index f6ed1e4d6f..f364638f37 100644 --- a/src/calibre/gui2/custom_column_widgets.py +++ b/src/calibre/gui2/custom_column_widgets.py @@ -41,7 +41,8 @@ class Base(object): val = self.gui_val val = self.normalize_ui_val(val) if val != self.initial_val: - self.db._set_custom(book_id, val, num=self.col_id, notify=notify) + self.db.set_custom(book_id, val, num=self.col_id, notify=notify, + commit=False) def normalize_db_val(self, val): return val @@ -304,8 +305,8 @@ class Series(Base): num=self.col_id) else: s_index = None - self.db._set_custom(book_id, val, extra=s_index, - num=self.col_id, notify=notify) + self.db.set_custom(book_id, val, extra=s_index, + num=self.col_id, notify=notify, commit=False) widgets = { 'bool' : Bool, diff --git a/src/calibre/library/custom_columns.py b/src/calibre/library/custom_columns.py index 60be09a193..4ba664dadc 100644 --- a/src/calibre/library/custom_columns.py +++ b/src/calibre/library/custom_columns.py @@ -412,10 +412,11 @@ class CustomColumns(object): self.conn.commit() def set_custom(self, id, val, label=None, num=None, - append=False, notify=True, extra=None): + append=False, notify=True, extra=None, commit=True): self._set_custom(id, val, label=label, num=num, append=append, notify=notify, extra=extra) - self.conn.commit() + if commit: + self.conn.commit() def _set_custom(self, id_, val, label=None, num=None, append=False, notify=True, extra=None):