Method that allows implementing has_book in a worker process with no access to the data

This commit is contained in:
Kovid Goyal 2014-11-09 21:11:39 +05:30
parent e50915bfe8
commit b127f0b3f9

View File

@ -1422,11 +1422,18 @@ class Cache(object):
result.append(author_to_author_sort(aut) if aid is None else table.asort_map[aid])
return ' & '.join(filter(None, result))
@read_api
def data_for_has_book(self):
''' Return data suitable for use in :meth:`has_book`. This can be used for an
implementation of :meth:`has_book` in a worker process without access to the
db. '''
return {icu_lower(title):book_id for book_id, title in self.fields['title'].table.book_col_map.itervalues()}
@read_api
def has_book(self, mi):
''' Return True iff the database contains an entry with the same title
as the passed in Metadata object. The comparison is case-insensitive.
'''
See also :meth:`data_for_has_book`. '''
title = mi.title
if title:
if isbytestring(title):