From d85fd5b737df8706bc07d20380e56a6a82114e85 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 15 Jun 2008 23:02:25 -0700 Subject: [PATCH] Refresh cache on metadata edits --- src/calibre/gui2/library.py | 11 +++++++---- src/calibre/library/database2.py | 12 +++++++++++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/calibre/gui2/library.py b/src/calibre/gui2/library.py index d344f3d6a9..28c760c74e 100644 --- a/src/calibre/gui2/library.py +++ b/src/calibre/gui2/library.py @@ -117,17 +117,20 @@ class BooksModel(QAbstractTableModel): def set_database(self, db): if isinstance(db, (QString, basestring)): if isinstance(db, QString): - db = qstring_to_unicode(db) + db = qstring_to_unicode(db) db = LibraryDatabase(os.path.expanduser(db)) self.db = db def refresh_ids(self, ids, current_row=-1): rows = self.db.refresh_ids(ids) for row in rows: + if self.cover_cache: + id = self.db.id(row) + self.cover_cache.refresh(id) if row == current_row: - self.emit(SIGNAL('new_bookdisplay_data(PyQt_PyObject)'), + self.emit(SIGNAL('new_bookdisplay_data(PyQt_PyObject)'), self.get_book_display_info(row)) - self.emit(SIGNAL('dataChanged(QModelIndex,QModelIndex)'), + self.emit(SIGNAL('dataChanged(QModelIndex,QModelIndex)'), self.index(row, 0), self.index(row, self.columnCount(None)-1)) def close(self): @@ -136,7 +139,7 @@ class BooksModel(QAbstractTableModel): self.reset() def add_books(self, paths, formats, metadata, uris=[], add_duplicates=False): - return self.db.add_books(paths, formats, metadata, uris, + return self.db.add_books(paths, formats, metadata, uris, add_duplicates=add_duplicates) def row_indices(self, index): diff --git a/src/calibre/library/database2.py b/src/calibre/library/database2.py index 55ca7ace79..7d287ebfcb 100644 --- a/src/calibre/library/database2.py +++ b/src/calibre/library/database2.py @@ -130,7 +130,17 @@ class CoverCache(QThread): def clear_cache(self): self.cache_lock.lockForWrite() self.cache = {} - self.cache_lock.unlock() + self.cache_lock.unlock() + + def refresh(self, ids): + self.cache_lock.lockForWrite() + for id in ids: + self.cache.pop(id, None) + self.cache_lock.unlock() + self.load_queue_lock.lockForWrite() + for id in ids: + self.load_queue.append_left(id) + self.load_queue_lock.unlock() class Concatenate(object): '''String concatenation aggregator for sqlite'''