From 474abe15c24466ac14c8de8eae633ef2f50774a0 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 24 Jul 2013 18:47:23 +0530 Subject: [PATCH] Invalidate search caches when marked ids change --- src/calibre/db/view.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/calibre/db/view.py b/src/calibre/db/view.py index 2a779a5af0..602a2fbeaf 100644 --- a/src/calibre/db/view.py +++ b/src/calibre/db/view.py @@ -310,6 +310,7 @@ class View(object): a mapping is provided, then the search can be used to search for particular values: ``marked:value`` ''' + old_marked_ids = set(self.marked_ids) if not hasattr(id_dict, 'items'): # Simple list. Make it a dict of string 'true' self.marked_ids = dict.fromkeys(id_dict, u'true') @@ -317,6 +318,9 @@ class View(object): # Ensure that all the items in the dict are text self.marked_ids = dict(izip(id_dict.iterkeys(), imap(unicode, id_dict.itervalues()))) + # This invalidates all searches in the cache even though the cache may + # be shared by multiple views. This is not ideal, but... + self.cache.clear_search_caches(old_marked_ids | set(self.marked_ids)) def refresh(self, field=None, ascending=True): self._map = tuple(self.cache.all_book_ids())