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 @@ class AjaxServer(object):
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 @@ class LibraryServer(ContentServer, MobileServer, XMLServer, OPDSServer, Cache,
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 @@ class BrowseServer(object):
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 @@ class BrowseServer(object):
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 @@ class Cache(object):
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 @@ class MobileServer(object):
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 @@ class XMLServer(object):
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