diff --git a/src/calibre/db/cache.py b/src/calibre/db/cache.py index 564c4f53ed..0e49af8031 100644 --- a/src/calibre/db/cache.py +++ b/src/calibre/db/cache.py @@ -620,7 +620,6 @@ class Cache(object): @write_api def set_field(self, name, book_id_to_val_map, allow_case_change=True): # TODO: Specialize title/authors to also update path - # TODO: Handle updating caches used by composite fields # TODO: Ensure the sort fields are updated for title/author/series? f = self.fields[name] is_series = f.metadata['datatype'] == 'series' @@ -646,6 +645,10 @@ class Cache(object): sf = self.fields[f.name+'_index'] dirtied |= sf.writer.set_books(simap, self.backend, allow_case_change=False) + if dirtied and self.composites: + for name in self.composites: + self.fields[name].pop_cache(dirtied) + return dirtied # }}} diff --git a/src/calibre/db/fields.py b/src/calibre/db/fields.py index 2ae1fa2ecd..e0074de7d1 100644 --- a/src/calibre/db/fields.py +++ b/src/calibre/db/fields.py @@ -167,9 +167,10 @@ class CompositeField(OneToOneField): with self._lock: self._render_cache = {} - def pop_cache(self, book_id): + def pop_cache(self, book_ids): with self._lock: - self._render_cache.pop(book_id, None) + for book_id in book_ids: + self._render_cache.pop(book_id, None) def get_value_with_cache(self, book_id, get_metadata): with self._lock: @@ -177,6 +178,8 @@ class CompositeField(OneToOneField): if ans is None: mi = get_metadata(book_id) ans = mi.get('#'+self.metadata['label']) + with self._lock: + self._render_cache[book_id] = ans return ans def sort_keys_for_books(self, get_metadata, lang_map, all_book_ids):