From be53e12d636f53881ed758dd03fe7e31e5cd9b06 Mon Sep 17 00:00:00 2001 From: Scott Idem Date: Tue, 10 Feb 2026 17:30:30 -0500 Subject: [PATCH] perf(launcher): implement staggered data loading for sessions and presentations - Optimized session list load to be shell-only, preventing initial request storms.\n- Moved deep data fetching (presenters/files) into the Presentation component level using Svelte effects.\n- Deferred child collection lookups until components are rendered in the DOM.\n- Fixed ae_api import in launcher_presentation_view.\n- Hardened background refresh logic to respect requested views. --- .../ae_events__event_presentation.ts | 4 ++++ src/lib/ae_events/ae_events__event_session.ts | 11 ++++++++- .../launcher/[event_location_id]/+page.ts | 24 +++++++++++++++---- .../launcher_presentation_view.svelte | 18 +++++++++++++- 4 files changed, 51 insertions(+), 6 deletions(-) diff --git a/src/lib/ae_events/ae_events__event_presentation.ts b/src/lib/ae_events/ae_events__event_presentation.ts index 29639eec..85904ee8 100644 --- a/src/lib/ae_events/ae_events__event_presentation.ts +++ b/src/lib/ae_events/ae_events__event_presentation.ts @@ -153,9 +153,13 @@ export async function load_ae_obj_li__event_presentation({ _refresh_presentation_li_background({ api_cfg, for_obj_type, for_obj_id, inc_file_li, inc_presenter_li, enabled, hidden, view, limit, offset, order_by_li, try_cache, log_lvl: 0 }); // Warm cache for nested loads in the background (FIRE AND FORGET) + // DEPRECATED Optimization: Don't fire child loads for every item in a list here. + // Let the specific Presentation component handle its own children to stagger requests. + /* cached_li.forEach(p => { _handle_nested_loads(p, { api_cfg, inc_file_li, inc_presenter_li, enabled, hidden, limit, offset, try_cache, log_lvl: 0 }); }); + */ return cached_li; } diff --git a/src/lib/ae_events/ae_events__event_session.ts b/src/lib/ae_events/ae_events__event_session.ts index 6c2805f5..56603dde 100644 --- a/src/lib/ae_events/ae_events__event_session.ts +++ b/src/lib/ae_events/ae_events__event_session.ts @@ -198,7 +198,8 @@ export async function load_ae_obj_li__event_session({ // Background refresh (non-blocking) _refresh_session_li_background({ api_cfg, for_obj_type, for_obj_id, view, - inc_file_li, inc_all_file_li, inc_presentation_li, inc_presenter_li, + // Optimization: Disable nested loads for list members to prevent request storms + inc_file_li: false, inc_all_file_li: false, inc_presentation_li: false, inc_presenter_li: false, enabled, hidden, limit, offset, order_by_li, try_cache, log_lvl: log_lvl > 1 ? log_lvl : 0 }); @@ -231,6 +232,14 @@ async function _refresh_session_li_background({ api_cfg, for_obj_type, for_obj_i await db_save_ae_obj_li__ae_obj({ db_instance: db_events, table_name: 'session', obj_li: processed, properties_to_save, log_lvl }); if (log_lvl) console.log(`💾 [Trace] _refresh_session_li: Saved to IDB cache.`); } + + // Fire nested loads for each session only if explicitly requested (usually only for single objects) + if (inc_file_li || inc_presentation_li) { + processed.forEach(s => { + _handle_nested_loads(s, { api_cfg, inc_file_li, inc_all_file_li, inc_presentation_li, inc_presenter_li, enabled, hidden, limit, offset, try_cache, log_lvl: 0 }); + }); + } + return processed; } } catch (e) { diff --git a/src/routes/events/[event_id]/(launcher)/launcher/[event_location_id]/+page.ts b/src/routes/events/[event_id]/(launcher)/launcher/[event_location_id]/+page.ts index 28dc153c..302b3813 100644 --- a/src/routes/events/[event_id]/(launcher)/launcher/[event_location_id]/+page.ts +++ b/src/routes/events/[event_id]/(launcher)/launcher/[event_location_id]/+page.ts @@ -53,10 +53,10 @@ export async function load({ params, parent, url }) { api_cfg: ae_acct.api, for_obj_type: 'event_location', for_obj_id: event_location_id, - inc_file_li: true, - inc_all_file_li: true, - inc_presentation_li: true, - inc_presenter_li: true, + inc_file_li: false, // Optimized: Shell load for lists + inc_all_file_li: false, + inc_presentation_li: false, // Optimized: Shell load for lists + inc_presenter_li: false, enabled: 'enabled', hidden: 'all', view: 'alt', // Standardized View for file counts and extended metadata @@ -69,6 +69,22 @@ export async function load({ params, parent, url }) { ); } + const session_id = url.searchParams.get('session_id'); + if (browser && session_id) { + if (log_lvl) console.log(`Triggering deep load for session_id: ${session_id}`); + events_func.load_ae_obj_id__event_session({ + api_cfg: ae_acct.api, + event_session_id: session_id, + inc_file_li: true, + inc_all_file_li: true, + inc_presentation_li: true, + inc_presenter_li: true, + view: 'alt', + try_cache: true, + log_lvl: 0 + }); + } + // WARNING: Precaution against shared data between sites and sessions. data[account_id] = ae_acct; diff --git a/src/routes/events/[event_id]/(launcher)/launcher_presentation_view.svelte b/src/routes/events/[event_id]/(launcher)/launcher_presentation_view.svelte index 169041ff..1e6eb572 100644 --- a/src/routes/events/[event_id]/(launcher)/launcher_presentation_view.svelte +++ b/src/routes/events/[event_id]/(launcher)/launcher_presentation_view.svelte @@ -7,10 +7,26 @@ import { liveQuery } from 'dexie'; import { db_events } from '$lib/ae_events/db_events'; - import { ae_loc } from '$lib/stores/ae_stores'; + import { ae_loc, ae_api } from '$lib/stores/ae_stores'; import { events_loc, events_sess } from '$lib/stores/ae_events_stores'; + import { events_func } from '$lib/ae_events_functions'; import Event_launcher_file_cont from './launcher_file_cont.svelte'; + // Staggered Load: Trigger deep fetch only when component is active + $effect(() => { + const id = lq__event_presentation_obj?.event_presentation_id; + if (id) { + events_func.load_ae_obj_id__event_presentation({ + api_cfg: $ae_api, + event_presentation_id: id, + inc_file_li: true, + inc_presenter_li: true, + try_cache: true, + log_lvl: 0 + }); + } + }); + // Event File (Directly linked to presentation) let lq__event_file_obj_li = $derived( liveQuery(async () => {