Fix freshness persistence, optimize pubkey loading

This commit is contained in:
Jon Staab
2024-12-11 11:03:22 -08:00
parent a378ecbad4
commit 2ee370e78b
2 changed files with 11 additions and 8 deletions

View File

@@ -1,5 +1,5 @@
import {get} from "svelte/store" 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 { import {
DELETE, DELETE,
PROFILE, 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 () => { promise.then(async () => {
for (const pubkeys of chunk(50, getDefaultPubkeys())) { for (const pubkeys of chunk(50, getDefaultPubkeys())) {
await sleep(300) const relays = sample(1, INDEXER_RELAYS)
await sleep(1000)
for (const pubkey of pubkeys) { for (const pubkey of pubkeys) {
loadMembership(pubkey) loadMembership(pubkey, {relays})
loadProfile(pubkey) loadProfile(pubkey, {relays})
loadFollows(pubkey) loadFollows(pubkey, {relays})
loadMutes(pubkey) loadMutes(pubkey, {relays})
} }
} }
}) })

View File

@@ -118,7 +118,7 @@
const migrateFreshness = (data: {key: string; value: number}[]) => { const migrateFreshness = (data: {key: string; value: number}[]) => {
const cutoff = ago(HOUR) 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) const migratePlaintext = (data: {key: string; value: number}[]) => data.slice(0, 10_000)