From f979f0d357e4fcf86ff49e98462242f6a959df5a Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Mon, 11 Apr 2011 14:49:54 +0100 Subject: [PATCH] Improve performance of ui.library_moved(). Changes remove multiple calls to tags_view.recount(). --- src/calibre/gui2/search_box.py | 5 +++-- src/calibre/gui2/search_restriction_mixin.py | 5 +++-- src/calibre/gui2/ui.py | 5 +++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/calibre/gui2/search_box.py b/src/calibre/gui2/search_box.py index 8936493290..ea7cab95d0 100644 --- a/src/calibre/gui2/search_box.py +++ b/src/calibre/gui2/search_box.py @@ -436,14 +436,15 @@ class SavedSearchBoxMixin(object): # {{{ b = getattr(self, x+'_search_button') b.setStatusTip(b.toolTip()) - def saved_searches_changed(self, set_restriction=None): + def saved_searches_changed(self, set_restriction=None, recount=True): p = sorted(saved_searches().names(), key=sort_key) if set_restriction is None: set_restriction = unicode(self.search_restriction.currentText()) # rebuild the restrictions combobox using current saved searches self.search_restriction.clear() self.search_restriction.addItem('') - self.tags_view.recount() + if recount: + self.tags_view.recount() for s in p: self.search_restriction.addItem(s) if set_restriction: # redo the search restriction if there was one diff --git a/src/calibre/gui2/search_restriction_mixin.py b/src/calibre/gui2/search_restriction_mixin.py index 73c191101c..74e448da6e 100644 --- a/src/calibre/gui2/search_restriction_mixin.py +++ b/src/calibre/gui2/search_restriction_mixin.py @@ -25,8 +25,9 @@ class SearchRestrictionMixin(object): r = self.search_restriction.findText(name) if r < 0: r = 0 - self.search_restriction.setCurrentIndex(r) - self.apply_search_restriction(r) + if r != self.search_restriction.currentIndex(): + self.search_restriction.setCurrentIndex(r) + self.apply_search_restriction(r) def apply_search_restriction(self, i): r = unicode(self.search_restriction.currentText()) diff --git a/src/calibre/gui2/ui.py b/src/calibre/gui2/ui.py index 4a9d76418c..4d363c283a 100644 --- a/src/calibre/gui2/ui.py +++ b/src/calibre/gui2/ui.py @@ -446,12 +446,13 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, EmailMixin, # {{{ self.search.clear() self.saved_search.clear() self.book_details.reset_info() - self.library_view.model().count_changed() prefs['library_path'] = self.library_path + #self.library_view.model().count_changed() db = self.library_view.model().db + self.iactions['Choose Library'].count_changed(db.count()) self.set_window_title() self.apply_named_search_restriction('') # reset restriction to null - self.saved_searches_changed() # reload the search restrictions combo box + self.saved_searches_changed(recount=False) # reload the search restrictions combo box self.apply_named_search_restriction(db.prefs['gui_restriction']) for action in self.iactions.values(): action.library_changed(db)