perf: skip feed index fetch when navigating from activity feed
Write the activity summary to sessionStorage on click in ActivityFeed, then read it synchronously at module init in ActivityDetailLoader so the page renders immediately without the "Loading activity…" blank screen or the 2 round-trip index fetch. Direct URL / bookmark / shared link falls through to the existing slow path unchanged.
This commit is contained in:
@@ -7,9 +7,20 @@
|
|||||||
|
|
||||||
export let base: string = '/';
|
export let base: string = '/';
|
||||||
|
|
||||||
let activity: ActivitySummary | null = null;
|
// Synchronous init — check sessionStorage before first render so "Loading activity…"
|
||||||
let notFound = false;
|
// is never shown when navigating from the feed.
|
||||||
let loading = true;
|
const _activityId = window.location.pathname.match(/\/activity\/([^/]+)/)?.[1] ?? null;
|
||||||
|
let _initial: ActivitySummary | null = null;
|
||||||
|
if (_activityId) {
|
||||||
|
try {
|
||||||
|
const c = sessionStorage.getItem(`bincio:activity:${_activityId}`);
|
||||||
|
if (c) _initial = JSON.parse(c);
|
||||||
|
} catch {}
|
||||||
|
}
|
||||||
|
|
||||||
|
let activity: ActivitySummary | null = _initial;
|
||||||
|
let notFound = _activityId === null;
|
||||||
|
let loading = _activityId !== null && _initial === null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build an ActivitySummary stub from a detail JSON object.
|
* Build an ActivitySummary stub from a detail JSON object.
|
||||||
@@ -85,11 +96,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
// Extract activity ID from the URL path: /activity/{id}/
|
if (!loading) return; // fast path: summary already from sessionStorage
|
||||||
const match = window.location.pathname.match(/\/activity\/([^/]+)/);
|
|
||||||
const id = match?.[1];
|
|
||||||
if (!id) { notFound = true; loading = false; return; }
|
|
||||||
|
|
||||||
|
const id = _activityId!;
|
||||||
try {
|
try {
|
||||||
// Load only the most-recent year shard — avoids downloading all years just
|
// Load only the most-recent year shard — avoids downloading all years just
|
||||||
// to look up one activity. Falls back to a direct file fetch if not found.
|
// to look up one activity. Falls back to a direct file fetch if not found.
|
||||||
|
|||||||
@@ -350,6 +350,7 @@
|
|||||||
<a
|
<a
|
||||||
href={a.detail_url ? `${import.meta.env.BASE_URL}activity/${a.id}/` : `${import.meta.env.BASE_URL}activity/local/?id=${a.id}`}
|
href={a.detail_url ? `${import.meta.env.BASE_URL}activity/${a.id}/` : `${import.meta.env.BASE_URL}activity/local/?id=${a.id}`}
|
||||||
class="before:absolute before:inset-0 before:content-[''] truncate"
|
class="before:absolute before:inset-0 before:content-[''] truncate"
|
||||||
|
on:click={() => { try { sessionStorage.setItem(`bincio:activity:${a.id}`, JSON.stringify(a)); } catch {} }}
|
||||||
>{a.title}</a>
|
>{a.title}</a>
|
||||||
</h3>
|
</h3>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user