Search: auto-load all year shards when a query is entered so full history is searched

This commit is contained in:
Davide Scaini
2026-05-13 21:17:55 +02:00
parent e4b53dde44
commit fb033e3da2
+22
View File
@@ -128,6 +128,28 @@
$: if (sport || datePre || query) shown = PAGE_SIZE; // reset pagination on filter change $: if (sport || datePre || query) shown = PAGE_SIZE; // reset pagination on filter change
// When a search query is active, eagerly load all remaining shards so the
// full history is searched (not just the initially-loaded recent year).
let loadingAllShards = false;
$: if (query.trim() && pendingShards.length > 0 && !loadingAllShards) {
loadingAllShards = true;
(async () => {
while (pendingShards.length > 0) {
const url = pendingShards[0];
pendingShards = pendingShards.slice(1);
try {
const fresh = await loadShardActivities(url);
const existing = new Map(all.map(a => [a.id, a]));
for (const a of fresh) if (!existing.has(a.id)) existing.set(a.id, a);
all = [...existing.values()].sort((a, b) =>
(b.started_at ?? '').localeCompare(a.started_at ?? ''),
);
} catch { /* ignore — partial results still useful */ }
}
loadingAllShards = false;
})();
}
$: if (mounted) { $: if (mounted) {
const params = new URLSearchParams(window.location.search); const params = new URLSearchParams(window.location.search);
if (sport === 'all') params.delete('sport'); else params.set('sport', sport); if (sport === 'all') params.delete('sport'); else params.set('sport', sport);