newdb: Do not cache searches that search on virtual fields like marked,

since there is no safe way to update such a cache.
This commit is contained in:
Kovid Goyal 2013-07-29 14:20:38 +05:30
parent 2831d39da4
commit c07f612f6b

View File

@ -481,12 +481,17 @@ class Parser(SearchQueryParser): # {{{
field = self.dbcache.fields[name] field = self.dbcache.fields[name]
except KeyError: except KeyError:
field = self.virtual_fields[name] field = self.virtual_fields[name]
self.virtual_field_used = True
return field.iter_searchable_values(get_metadata, candidates) return field.iter_searchable_values(get_metadata, candidates)
def iter_searchable_values(self, *args, **kwargs): def iter_searchable_values(self, *args, **kwargs):
for x in []: for x in ():
yield x, set() yield x, set()
def parse(self, *args, **kwargs):
self.virtual_field_used = False
return SearchQueryParser.parse(self, *args, **kwargs)
def get_matches(self, location, query, candidates=None, def get_matches(self, location, query, candidates=None,
allow_recursion=True): allow_recursion=True):
# If candidates is not None, it must not be modified. Changing its # If candidates is not None, it must not be modified. Changing its
@ -852,6 +857,8 @@ class Search(object):
sqp.dbcache = sqp.lookup_saved_search = None sqp.dbcache = sqp.lookup_saved_search = None
def _do_search(self, sqp, query, search_restriction, dbcache, book_ids=None): def _do_search(self, sqp, query, search_restriction, dbcache, book_ids=None):
''' Do the search, caching the results. Results are cached only if the
search is on the full library and no virtual field is searched on '''
if isinstance(search_restriction, bytes): if isinstance(search_restriction, bytes):
search_restriction = search_restriction.decode('utf-8') search_restriction = search_restriction.decode('utf-8')
@ -861,7 +868,7 @@ class Search(object):
if cached is None: if cached is None:
sqp.all_book_ids = all_book_ids if book_ids is None else book_ids sqp.all_book_ids = all_book_ids if book_ids is None else book_ids
restricted_ids = sqp.parse(search_restriction) restricted_ids = sqp.parse(search_restriction)
if sqp.all_book_ids is all_book_ids: if not sqp.virtual_field_used and sqp.all_book_ids is all_book_ids:
self.cache.add(search_restriction.strip(), restricted_ids) self.cache.add(search_restriction.strip(), restricted_ids)
else: else:
restricted_ids = cached restricted_ids = cached
@ -884,7 +891,7 @@ class Search(object):
sqp.all_book_ids = restricted_ids sqp.all_book_ids = restricted_ids
result = sqp.parse(query) result = sqp.parse(query)
if sqp.all_book_ids is all_book_ids: if not sqp.virtual_field_used and sqp.all_book_ids is all_book_ids:
self.cache.add(query.strip(), result) self.cache.add(query.strip(), result)
return result return result