mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Speed up manage_authors by orders of magnitude. In the process, make database_changed notification sane, doing the operation once even if many emits were done.
This commit is contained in:
parent
741ff46083
commit
eac8447e47
@ -106,9 +106,12 @@ class TagsView(QTreeView): # {{{
|
|||||||
self.refresh_required.connect(self.recount, type=Qt.QueuedConnection)
|
self.refresh_required.connect(self.recount, type=Qt.QueuedConnection)
|
||||||
self.sort_by.currentIndexChanged.connect(self.sort_changed)
|
self.sort_by.currentIndexChanged.connect(self.sort_changed)
|
||||||
self.made_connections = True
|
self.made_connections = True
|
||||||
|
self.refresh_signal_processed = True
|
||||||
db.add_listener(self.database_changed)
|
db.add_listener(self.database_changed)
|
||||||
|
|
||||||
def database_changed(self, event, ids):
|
def database_changed(self, event, ids):
|
||||||
|
if self.refresh_signal_processed:
|
||||||
|
self.refresh_signal_processed = False
|
||||||
self.refresh_required.emit()
|
self.refresh_required.emit()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -295,6 +298,7 @@ class TagsView(QTreeView): # {{{
|
|||||||
return self.isExpanded(idx)
|
return self.isExpanded(idx)
|
||||||
|
|
||||||
def recount(self, *args):
|
def recount(self, *args):
|
||||||
|
self.refresh_signal_processed = True
|
||||||
ci = self.currentIndex()
|
ci = self.currentIndex()
|
||||||
if not ci.isValid():
|
if not ci.isValid():
|
||||||
ci = self.indexAt(QPoint(10, 10))
|
ci = self.indexAt(QPoint(10, 10))
|
||||||
@ -937,7 +941,9 @@ class TagBrowserMixin(object): # {{{
|
|||||||
if old_author != new_author:
|
if old_author != new_author:
|
||||||
# The id might change if the new author already exists
|
# The id might change if the new author already exists
|
||||||
id = db.rename_author(id, new_author)
|
id = db.rename_author(id, new_author)
|
||||||
db.set_sort_field_for_author(id, unicode(new_sort))
|
db.set_sort_field_for_author(id, unicode(new_sort),
|
||||||
|
commit=False, notify=False)
|
||||||
|
db.commit()
|
||||||
self.library_view.model().refresh()
|
self.library_view.model().refresh()
|
||||||
self.tags_view.recount()
|
self.tags_view.recount()
|
||||||
|
|
||||||
|
@ -1639,15 +1639,16 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
return []
|
return []
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def set_sort_field_for_author(self, old_id, new_sort):
|
def set_sort_field_for_author(self, old_id, new_sort, commit=True, notify=False):
|
||||||
self.conn.execute('UPDATE authors SET sort=? WHERE id=?', \
|
self.conn.execute('UPDATE authors SET sort=? WHERE id=?', \
|
||||||
(new_sort.strip(), old_id))
|
(new_sort.strip(), old_id))
|
||||||
|
if commit:
|
||||||
self.conn.commit()
|
self.conn.commit()
|
||||||
# Now change all the author_sort fields in books by this author
|
# Now change all the author_sort fields in books by this author
|
||||||
bks = self.conn.get('SELECT book from books_authors_link WHERE author=?', (old_id,))
|
bks = self.conn.get('SELECT book from books_authors_link WHERE author=?', (old_id,))
|
||||||
for (book_id,) in bks:
|
for (book_id,) in bks:
|
||||||
ss = self.author_sort_from_book(book_id, index_is_id=True)
|
ss = self.author_sort_from_book(book_id, index_is_id=True)
|
||||||
self.set_author_sort(book_id, ss)
|
self.set_author_sort(book_id, ss, notify=notify, commit=commit)
|
||||||
|
|
||||||
def rename_author(self, old_id, new_name):
|
def rename_author(self, old_id, new_name):
|
||||||
# Make sure that any commas in new_name are changed to '|'!
|
# Make sure that any commas in new_name are changed to '|'!
|
||||||
|
Loading…
x
Reference in New Issue
Block a user