refactor(badges): move reports IDB prefetch to +page.ts load function
Replace the $effect-based background fetch with the canonical if(browser) fire-and-forget pattern in +page.ts. Runs earlier in the lifecycle, no store subscription overhead, and immune to $ae_api store re-trigger side effects. Removes ae_api and events_func imports from the component. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -9,10 +9,9 @@ let { data, log_lvl = 0 }: Props = $props();
|
||||
import { liveQuery } from 'dexie';
|
||||
import { page } from '$app/state';
|
||||
|
||||
import { ae_loc, ae_api } from '$lib/stores/ae_stores';
|
||||
import { ae_loc } from '$lib/stores/ae_stores';
|
||||
import { db_events } from '$lib/ae_events/db_events';
|
||||
import { events_loc } from '$lib/stores/ae_events_stores';
|
||||
import { events_func } from '$lib/ae_events/ae_events_functions';
|
||||
|
||||
import { ArrowLeft, TrendingUp, Type, Gauge, LoaderCircle } from '@lucide/svelte';
|
||||
import Reports_badge_long_names from './reports_badge_long_names.svelte';
|
||||
@@ -20,20 +19,6 @@ import Reports_badge_print_throughput from './reports_badge_print_throughput.sve
|
||||
|
||||
let event_id = $derived(page.params.event_id);
|
||||
|
||||
// Reports read from IDB, so we need to ensure IDB is populated even when
|
||||
// arriving directly (without having visited the badge search page first).
|
||||
// Fire a background refresh — liveQuery below will reactively pick up new data.
|
||||
$effect(() => {
|
||||
const eid = event_id;
|
||||
if (!eid || !$ae_api?.base_url) return;
|
||||
// try_cache defaults to true — results are written to IDB so liveQuery picks them up.
|
||||
events_func.search__event_badge({
|
||||
api_cfg: $ae_api,
|
||||
event_id: eid,
|
||||
limit: 5000
|
||||
});
|
||||
});
|
||||
|
||||
type ReportKey = 'long_names' | 'print_throughput';
|
||||
let active_report: ReportKey | null = $state(null);
|
||||
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import { browser } from '$app/environment';
|
||||
import { events_func } from '$lib/ae_events/ae_events_functions';
|
||||
|
||||
export async function load({ params, parent }) {
|
||||
const data = await parent();
|
||||
const event_id = params.event_id;
|
||||
|
||||
if (browser && event_id && data.ae_api?.base_url) {
|
||||
// Fire and forget — writes to IDB so the liveQuery in +page.svelte reacts.
|
||||
events_func.search__event_badge({
|
||||
api_cfg: data.ae_api,
|
||||
event_id,
|
||||
limit: 5000
|
||||
});
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
Reference in New Issue
Block a user