perf: combined feed index for multi-user global feed

Instead of the browser resolving 20+ user shards recursively (~27 MB),
generate a pre-sorted feed.json at merge time with 50 activities per
page. The global feed loads one ~30 KB file on first paint; "Load more"
fetches subsequent pages (feed-2.json, feed-3.json, etc.).

Per-user profile pages still use year-sharded loadIndexPaged as before.
This commit is contained in:
Davide Scaini
2026-04-20 15:31:35 +02:00
parent e8a5fbbaba
commit db7047f210
4 changed files with 160 additions and 8 deletions
+43
View File
@@ -253,6 +253,49 @@ export async function loadShardActivities(shardUrl: string): Promise<ActivitySum
}
}
interface FeedPage {
page: number;
total_pages: number;
total_activities: number;
activities: ActivitySummary[];
}
/**
* Load the combined feed (multi-user global feed). Returns the first page of
* activities pre-sorted across all users, plus remaining page count.
*
* Falls back to the full shard-resolution path if feed.json doesn't exist
* (single-user installs, older data).
*/
export async function loadCombinedFeed(
baseUrl: string,
): Promise<{ activities: ActivitySummary[]; remainingPages: number } | null> {
try {
const feed = await fetchJSON<FeedPage>(`${baseUrl}data/feed.json`);
return {
activities: feed.activities ?? [],
remainingPages: (feed.total_pages ?? 1) - 1,
};
} catch {
return null;
}
}
/**
* Load a subsequent page of the combined feed (feed-2.json, feed-3.json, etc.).
*/
export async function loadCombinedFeedPage(
baseUrl: string,
page: number,
): Promise<ActivitySummary[]> {
try {
const feed = await fetchJSON<FeedPage>(`${baseUrl}data/feed-${page}.json`);
return feed.activities ?? [];
} catch {
return [];
}
}
/**
* Load a single activity detail, checking IndexedDB first so locally-converted
* activities are available offline.