Prune deleted books from recently read by user list

This commit is contained in:
Kovid Goyal 2023-01-04 13:32:42 +05:30
parent 9a1ef22b39
commit c5427c5ebe
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -146,6 +146,16 @@ def custom_list_template():
return ans 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): def basic_interface_data(ctx, rd):
ans = { ans = {
'username': rd.username, 'username': rd.username,
@ -169,7 +179,9 @@ def basic_interface_data(ctx, rd):
} }
ans['library_map'], ans['default_library_id'] = ctx.library_info(rd) ans['library_map'], ans['default_library_id'] = ctx.library_info(rd)
if ans['username']: 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 return ans