From c5427c5ebeb6c47cd1982b779c5977dbe40eb42a Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 4 Jan 2023 13:32:42 +0530 Subject: [PATCH] Prune deleted books from recently read by user list --- src/calibre/srv/code.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/calibre/srv/code.py b/src/calibre/srv/code.py index 2b98282c64..142c5f232e 100644 --- a/src/calibre/srv/code.py +++ b/src/calibre/srv/code.py @@ -146,6 +146,16 @@ def custom_list_template(): return ans +def book_exists(x, ctx, rd): + try: + db = ctx.get_library(rd, x['library_id']) + if db is None: + raise Exception('') + except Exception: + return False + return bool(db.new_api.has_format(x['book_id'], x['format'])) + + def basic_interface_data(ctx, rd): ans = { 'username': rd.username, @@ -169,7 +179,9 @@ def basic_interface_data(ctx, rd): } ans['library_map'], ans['default_library_id'] = ctx.library_info(rd) if ans['username']: - ans['recently_read_by_user'] = tuple(x for x in last_read_cache().get_recently_read(ans['username']) if x['library_id'] in ans['library_map']) + ans['recently_read_by_user'] = tuple( + x for x in last_read_cache().get_recently_read(ans['username']) + if x['library_id'] in ans['library_map'] and book_exists(x, ctx, rd)) return ans