From 2ee370e78b856355ee6ecfd0cb0d627077afe980 Mon Sep 17 00:00:00 2001 From: Jon Staab Date: Wed, 11 Dec 2024 11:03:22 -0800 Subject: [PATCH] Fix freshness persistence, optimize pubkey loading --- src/app/commands.ts | 17 ++++++++++------- src/routes/+layout.svelte | 2 +- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/app/commands.ts b/src/app/commands.ts index e54d698..5a13e7b 100644 --- a/src/app/commands.ts +++ b/src/app/commands.ts @@ -1,5 +1,5 @@ import {get} from "svelte/store" -import {ctx, uniq, sleep, chunk, equals, choice} from "@welshman/lib" +import {ctx, sample, uniq, sleep, chunk, equals, choice} from "@welshman/lib" import { DELETE, PROFILE, @@ -169,16 +169,19 @@ export const loadUserData = ( ]), ]) - // Load followed profiles slowly in the background without clogging other stuff up + // Load followed profiles slowly in the background without clogging other stuff up. Only use a single + // indexer relay to avoid too many redundant validations, which slow things down and eat bandwidth promise.then(async () => { for (const pubkeys of chunk(50, getDefaultPubkeys())) { - await sleep(300) + const relays = sample(1, INDEXER_RELAYS) + + await sleep(1000) for (const pubkey of pubkeys) { - loadMembership(pubkey) - loadProfile(pubkey) - loadFollows(pubkey) - loadMutes(pubkey) + loadMembership(pubkey, {relays}) + loadProfile(pubkey, {relays}) + loadFollows(pubkey, {relays}) + loadMutes(pubkey, {relays}) } } }) diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 855ecbe..a502e6b 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -118,7 +118,7 @@ const migrateFreshness = (data: {key: string; value: number}[]) => { const cutoff = ago(HOUR) - return data.filter(({value}) => value < cutoff) + return data.filter(({value}) => value > cutoff) } const migratePlaintext = (data: {key: string; value: number}[]) => data.slice(0, 10_000)