mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Improve performance of search when the query is in the cache.
This commit is contained in:
parent
88d99415cf
commit
067c84b2df
@ -715,7 +715,7 @@ class LRUCache(object): # {{{
|
|||||||
|
|
||||||
'A simple Least-Recently-Used cache'
|
'A simple Least-Recently-Used cache'
|
||||||
|
|
||||||
def __init__(self, limit=30):
|
def __init__(self, limit=50):
|
||||||
self.item_map = {}
|
self.item_map = {}
|
||||||
self.age_map = deque()
|
self.age_map = deque()
|
||||||
self.limit = limit
|
self.limit = limit
|
||||||
@ -854,6 +854,14 @@ class Search(object):
|
|||||||
search is on the full library and no virtual field is searched on '''
|
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')
|
||||||
|
if isinstance(query, bytes):
|
||||||
|
query = query.decode('utf-8')
|
||||||
|
|
||||||
|
query = query.strip()
|
||||||
|
if book_ids == None and query and not search_restriction:
|
||||||
|
cached = self.cache.get(query)
|
||||||
|
if cached is not None:
|
||||||
|
return cached
|
||||||
|
|
||||||
restricted_ids = all_book_ids = dbcache._all_book_ids(type=set)
|
restricted_ids = all_book_ids = dbcache._all_book_ids(type=set)
|
||||||
if search_restriction and search_restriction.strip():
|
if search_restriction and search_restriction.strip():
|
||||||
@ -870,14 +878,11 @@ class Search(object):
|
|||||||
elif book_ids is not None:
|
elif book_ids is not None:
|
||||||
restricted_ids = book_ids
|
restricted_ids = book_ids
|
||||||
|
|
||||||
if isinstance(query, bytes):
|
if not query:
|
||||||
query = query.decode('utf-8')
|
|
||||||
|
|
||||||
if not query or not query.strip():
|
|
||||||
return restricted_ids
|
return restricted_ids
|
||||||
|
|
||||||
if restricted_ids is all_book_ids:
|
if restricted_ids is all_book_ids:
|
||||||
cached = self.cache.get(query.strip())
|
cached = self.cache.get(query)
|
||||||
if cached is not None:
|
if cached is not None:
|
||||||
return cached
|
return cached
|
||||||
|
|
||||||
@ -885,7 +890,7 @@ class Search(object):
|
|||||||
result = sqp.parse(query)
|
result = sqp.parse(query)
|
||||||
|
|
||||||
if not sqp.virtual_field_used and 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, result)
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user