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 {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})
}
}
})

View File

@@ -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)