Content server: Ignore current VL in GUI when embedded

Content server: When running from inside the main calibre program, do not
restrict the books shown based on the current virtual library in the
main program. If you wish to restrict the books shown in the content
server, use Preferences->Sharing over the net.
This commit is contained in:
Kovid Goyal 2013-09-03 12:37:20 +05:30
parent 7905b2e4ef
commit a4f2d0d664
6 changed files with 12 additions and 10 deletions

View file

@ -590,8 +590,7 @@ def ajax_search(self, query='', sort='title', offset=0, num=25,
if isbytestring(query):
query = query.decode('UTF-8')
ids = self.db.search_getting_ids(query.strip(), self.search_restriction, sort_results=False)
ids = list(ids)
ids = list(self.search_for_books(query))
self.db.data.multisort(fields=[(sfield, sort_order == 'asc')], subsort=True,
only_ids=ids)
total_num = len(ids)

View file

@ -314,3 +314,9 @@ def threaded_exit(self):
t.daemon = True
t.start()
def search_for_books(self, query):
return self.db.search_getting_ids(
(query or '').strip(), self.search_restriction,
sort_results=False, use_virtual_library=False)

View file

@ -931,8 +931,7 @@ def browse_details(self, id=None):
def browse_random(self, *args, **kwargs):
import random
try:
book_id = random.choice(self.db.search_getting_ids(
'', self.search_restriction, sort_results=False))
book_id = random.choice(self.search_for_books(''))
except IndexError:
raise cherrypy.HTTPError(404, 'This library has no books')
ans = self.browse_render_details(book_id, add_random_button=True)
@ -957,7 +956,7 @@ def browse_book(self, id=None, category_sort=None):
def browse_search(self, query='', list_sort=None):
if isbytestring(query):
query = query.decode('UTF-8')
ids = self.db.search_getting_ids(query.strip(), self.search_restriction)
ids = self.search_for_books(query)
items = [self.db.data.tablerow_for_id(x) for x in ids]
sort = self.browse_sort_book_list(items, list_sort)
ids = [x[0] for x in items]

View file

@ -21,9 +21,7 @@ def reset_caches(self):
def search_cache(self, search):
old = self._search_cache.pop(search, None)
if old is None or old[0] <= self.db.last_modified():
matches = self.db.data.search_getting_ids(search, self.search_restriction, sort_results=False)
if not matches:
matches = []
matches = self.search_for_books(search) or []
self._search_cache[search] = (utcnow(), frozenset(matches))
if len(self._search_cache) > 50:
self._search_cache.popitem(last=False)

View file

@ -222,7 +222,7 @@ def mobile(self, start='1', num='25', sort='date', search='',
search = ''
if isbytestring(search):
search = search.decode('UTF-8')
ids = self.db.search_getting_ids(search.strip(), self.search_restriction, sort_results=False)
ids = self.search_for_books(search)
FM = self.db.FIELD_MAP
items = [r for r in iter(self.db) if r[FM['id']] in ids]
if sort is not None:

View file

@ -53,7 +53,7 @@ def xml(self, start='0', num='50', sort=None, search=None,
if isbytestring(search):
search = search.decode('UTF-8')
ids = self.db.search_getting_ids(search.strip(), self.search_restriction, sort_results=False)
ids = self.search_for_books(search)
FM = self.db.FIELD_MAP