ActivityDetail: fetch timeseries in parallel with detail JSON to cut load time
This commit is contained in:
@@ -52,15 +52,27 @@
|
|||||||
.then(d => { segmentEfforts = d; })
|
.then(d => { segmentEfforts = d; })
|
||||||
.catch(() => {});
|
.catch(() => {});
|
||||||
|
|
||||||
|
// Start timeseries fetch immediately in parallel with detail — the URL is
|
||||||
|
// predictable from detail_url, saving a full sequential round-trip.
|
||||||
|
const detailUrl = activity.detail_url ?? '';
|
||||||
|
const earlyTsPromise: Promise<Timeseries | null> = detailUrl && !detailUrl.startsWith('idb:')
|
||||||
|
? loadTimeseries(
|
||||||
|
detailUrl.replace(/\.json$/, '.timeseries.json').replace(/^.*activities\//, 'activities/'),
|
||||||
|
detailUrl,
|
||||||
|
base,
|
||||||
|
).catch(() => null)
|
||||||
|
: Promise.resolve(null);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
detail = await loadActivity(activity.id, activity.detail_url ?? '', base);
|
detail = await loadActivity(activity.id, detailUrl, base);
|
||||||
if (!detail) throw new Error('Activity not found');
|
if (!detail) throw new Error('Activity not found');
|
||||||
// Use embedded timeseries (IDB activities) or lazy-fetch from URL
|
// Use embedded timeseries (IDB activities) or the already-in-flight fetch
|
||||||
if (detail.timeseries) {
|
if (detail.timeseries) {
|
||||||
timeseries = detail.timeseries;
|
timeseries = detail.timeseries;
|
||||||
} else if (detail.timeseries_url) {
|
} else if (detail.timeseries_url) {
|
||||||
timeseriesLoading = true;
|
timeseriesLoading = true;
|
||||||
timeseries = await loadTimeseries(detail.timeseries_url, activity.detail_url ?? '', base);
|
timeseries = await earlyTsPromise ??
|
||||||
|
await loadTimeseries(detail.timeseries_url, detailUrl, base);
|
||||||
timeseriesLoading = false;
|
timeseriesLoading = false;
|
||||||
}
|
}
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
|
|||||||
Reference in New Issue
Block a user