diff --git a/src/calibre/srv/code.py b/src/calibre/srv/code.py index c706c97bd6..2b98282c64 100644 --- a/src/calibre/srv/code.py +++ b/src/calibre/srv/code.py @@ -169,8 +169,7 @@ def basic_interface_data(ctx, rd): } ans['library_map'], ans['default_library_id'] = ctx.library_info(rd) if ans['username']: - lrc = last_read_cache() - ans['recently_read_by_user'] = lrc.get_recently_read(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']) return ans diff --git a/src/pyj/book_list/home.pyj b/src/pyj/book_list/home.pyj index f8ca51f27d..c9e0f19ecc 100644 --- a/src/pyj/book_list/home.pyj +++ b/src/pyj/book_list/home.pyj @@ -33,6 +33,13 @@ add_extra_css(def(): return ans ) +recently_read_by_user = {'updated': False} + + +def update_recently_read_by_user(items): + recently_read_by_user.items = items + recently_read_by_user.updated = True + def show_cover(blob, name, mt, book): img = document.getElementById(this) @@ -117,10 +124,10 @@ def prepare_recent_container(container): return cover_container -def show_recent_for_user(container_id, interface_data): +def show_recent_for_user(container_id): container = document.getElementById(container_id) images = prepare_recent_container(container) - for item in interface_data.recently_read_by_user[:3]: + for item in recently_read_by_user.items[:3]: q = {'library_id': item.library_id} if item.cfi: q.bookpos = item.cfi @@ -160,6 +167,15 @@ def show_recent_stage2(books): start_sync(to_sync) +def show_recent_for_user_if_fetched(): + container = this + if not recently_read_by_user.updated: + return conditional_timeout(container.id, 5, show_recent_for_user_if_fetched) + if recently_read_by_user.items and recently_read_by_user.items.length > 0: + return show_recent_for_user(container.id) + return show_recent.call(container) + + def show_recent(): container = this db = get_db() @@ -265,8 +281,8 @@ def init(container_id): recent = E.div(style='display:none', class_='recently-read') recent_container_id = ensure_id(recent) container.appendChild(recent) - if interface_data.username and interface_data.recently_read_by_user and interface_data.recently_read_by_user.length > 0: - show_recent_for_user(recent_container_id, interface_data) + if interface_data.username: + conditional_timeout(recent_container_id, 5, show_recent_for_user_if_fetched) else: conditional_timeout(recent_container_id, 5, show_recent) diff --git a/src/pyj/book_list/main.pyj b/src/pyj/book_list/main.pyj index f336b49518..e5d144f5b3 100644 --- a/src/pyj/book_list/main.pyj +++ b/src/pyj/book_list/main.pyj @@ -13,6 +13,7 @@ from popups import install_event_filters from utils import safe_set_inner_html from book_list.constants import book_list_container_id, read_book_container_id, INIT_ENDPOINT +from book_list.home import update_recently_read_by_user from book_list.library_data import fetch_init_data, update_library_data, url_books_query from book_list.theme import get_color, get_font_family, css_for_variables from book_list.router import update_window_title, set_default_mode_handler, apply_url, set_mode_handler, on_pop_state @@ -83,6 +84,7 @@ def init_ui(): def install_data_and_init_ui(raw_data): data = JSON.parse(raw_data) update_interface_data(data) + update_recently_read_by_user(data.recently_read_by_user) update_library_data(data) interface_data = get_interface_data() sd = UserSessionData(interface_data.username, interface_data.user_session_data) @@ -132,6 +134,7 @@ def do_update_interface_data(): if end_type is 'load': data = JSON.parse(xhr.responseText) update_interface_data(data) + update_recently_read_by_user(data.recently_read_by_user) if data.translations?: get_translations(data.translations) install(data.translations) diff --git a/src/pyj/session.pyj b/src/pyj/session.pyj index f53f8d99d5..0c1d9cd29e 100644 --- a/src/pyj/session.pyj +++ b/src/pyj/session.pyj @@ -243,7 +243,6 @@ default_interface_data = { 'custom_list_template': None, 'num_per_page': 50, 'lang_code_for_user_manual': '', - 'recently_read_by_user': v'[]', } def get_interface_data():