From 0f4b4910832fc9636bcf1ffd494890b76fa1d968 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 6 Oct 2020 10:38:16 +0530 Subject: [PATCH] Implement restrict_to_book_ids for annotation fetching --- src/calibre/db/backend.py | 6 +++++- src/calibre/db/cache.py | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/calibre/db/backend.py b/src/calibre/db/backend.py index 9dac48ecdb..043e8b2c51 100644 --- a/src/calibre/db/backend.py +++ b/src/calibre/db/backend.py @@ -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'] diff --git a/src/calibre/db/cache.py b/src/calibre/db/cache.py index fa6b491d4f..a17551f623 100644 --- a/src/calibre/db/cache.py +++ b/src/calibre/db/cache.py @@ -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(