Implement restrict_to_book_ids for annotation fetching

This commit is contained in:
Kovid Goyal 2020-10-06 10:38:16 +05:30
parent dc13fdcde0
commit 0f4b491083
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 7 additions and 3 deletions

View File

@ -1805,6 +1805,8 @@ class DB(object):
ls = json.loads
try:
for (rowid, book_id, fmt, user_type, user, annot_data, text) in self.execute(query, tuple(data)):
if restrict_to_book_ids is not None and book_id not in restrict_to_book_ids:
continue
try:
parsed_annot = ls(annot_data)
except Exception:
@ -1875,7 +1877,7 @@ class DB(object):
self.execute('UPDATE annotations SET annot_data=?, timestamp=?, annot_type=?, searchable_text=?, annot_id=? WHERE id=?',
(json.dumps(annot), timestamp, atype, text, aid, annot_id))
def all_annotations(self, restrict_to_user=None, limit=None, annotation_type=None, ignore_removed=False):
def all_annotations(self, restrict_to_user=None, limit=None, annotation_type=None, ignore_removed=False, restrict_to_book_ids=None):
ls = json.loads
q = 'SELECT id, book, format, user_type, user, annot_data FROM annotations'
data = []
@ -1891,6 +1893,8 @@ class DB(object):
q += ' ORDER BY timestamp DESC '
count = 0
for (rowid, book_id, fmt, user_type, user, annot_data) in self.execute(q, tuple(data)):
if restrict_to_book_ids is not None and book_id not in restrict_to_book_ids:
continue
try:
annot = ls(annot_data)
atype = annot['type']

View File

@ -2320,8 +2320,8 @@ class Cache(object):
return tuple(self.backend.all_annotation_types())
@read_api
def all_annotations(self, restrict_to_user=None, limit=None, annotation_type=None, ignore_removed=False):
return tuple(self.backend.all_annotations(restrict_to_user, limit, annotation_type, ignore_removed))
def all_annotations(self, restrict_to_user=None, limit=None, annotation_type=None, ignore_removed=False, restrict_to_book_ids=None):
return tuple(self.backend.all_annotations(restrict_to_user, limit, annotation_type, ignore_removed, restrict_to_book_ids))
@read_api
def search_annotations(