From b127f0b3f9e1949700558d5fc445b77c59a6a0a6 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 9 Nov 2014 21:11:39 +0530 Subject: [PATCH] Method that allows implementing has_book in a worker process with no access to the data --- src/calibre/db/cache.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/calibre/db/cache.py b/src/calibre/db/cache.py index 5a48322bd7..eaa4bfd718 100644 --- a/src/calibre/db/cache.py +++ b/src/calibre/db/cache.py @@ -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):