mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
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:
parent
2831d39da4
commit
c07f612f6b
@ -481,12 +481,17 @@ class Parser(SearchQueryParser): # {{{
|
||||
field = self.dbcache.fields[name]
|
||||
except KeyError:
|
||||
field = self.virtual_fields[name]
|
||||
self.virtual_field_used = True
|
||||
return field.iter_searchable_values(get_metadata, candidates)
|
||||
|
||||
def iter_searchable_values(self, *args, **kwargs):
|
||||
for x in []:
|
||||
for x in ():
|
||||
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,
|
||||
allow_recursion=True):
|
||||
# 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
|
||||
|
||||
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):
|
||||
search_restriction = search_restriction.decode('utf-8')
|
||||
|
||||
@ -861,7 +868,7 @@ class Search(object):
|
||||
if cached is None:
|
||||
sqp.all_book_ids = all_book_ids if book_ids is None else book_ids
|
||||
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)
|
||||
else:
|
||||
restricted_ids = cached
|
||||
@ -884,7 +891,7 @@ class Search(object):
|
||||
sqp.all_book_ids = restricted_ids
|
||||
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)
|
||||
|
||||
return result
|
||||
|
Loading…
x
Reference in New Issue
Block a user