Fix channel loading
This commit is contained in:
parent
8ce79193d1
commit
1055a6d567
6 changed files with 27 additions and 37 deletions
|
|
@ -83,9 +83,9 @@
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
<div class="flex w-full gap-2">
|
<div class="flex w-full gap-3">
|
||||||
{#if showPubkey}
|
{#if showPubkey}
|
||||||
<Avatar src={$profile?.picture} class="border border-solid border-base-content" size={10} />
|
<Avatar src={$profile?.picture} class="border border-solid border-base-content" size={8} />
|
||||||
{:else}
|
{:else}
|
||||||
<div class="w-10 min-w-10 max-w-10" />
|
<div class="w-10 min-w-10 max-w-10" />
|
||||||
{/if}
|
{/if}
|
||||||
|
|
@ -100,7 +100,7 @@
|
||||||
<div class="text-sm">
|
<div class="text-sm">
|
||||||
<Content {event} />
|
<Content {event} />
|
||||||
{#if thunk}
|
{#if thunk}
|
||||||
<div class="badge">
|
<div class="badge badge-neutral">
|
||||||
<ThunkStatus {thunk} />
|
<ThunkStatus {thunk} />
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
|
||||||
|
|
@ -85,7 +85,7 @@
|
||||||
<Avatar
|
<Avatar
|
||||||
src={$profile?.picture}
|
src={$profile?.picture}
|
||||||
class="border border-solid border-base-content"
|
class="border border-solid border-base-content"
|
||||||
size={10} />
|
size={8} />
|
||||||
</Button>
|
</Button>
|
||||||
{/if}
|
{/if}
|
||||||
<div class="-mt-1 flex-grow pr-1">
|
<div class="-mt-1 flex-grow pr-1">
|
||||||
|
|
|
||||||
|
|
@ -163,18 +163,16 @@ export const pullConservatively = ({relays, filters}: AppSyncOpts) => {
|
||||||
const [smart, dumb] = partition(hasNegentropy, relays)
|
const [smart, dumb] = partition(hasNegentropy, relays)
|
||||||
const promises = [pull({relays: smart, filters})]
|
const promises = [pull({relays: smart, filters})]
|
||||||
|
|
||||||
// Since pulling from relays without negentropy is expensive, only do it 30% of the time,
|
// Since pulling from relays without negentropy is expensive, limit how many
|
||||||
// unless we have very few matching events. If that's the case, either we haven't synced
|
// duplicates we repeatedly download
|
||||||
// this filter yet, or there are few enough events that we don't really need to worry about
|
if (dumb.length > 0) {
|
||||||
// downloading duplicates. Otherwise, add a reasonable since value to make sure we at
|
|
||||||
// least fetch recent events.
|
|
||||||
if (Math.random() > 0.7 || repository.query(filters).length < 100) {
|
|
||||||
promises.push(pull({relays: dumb, filters}))
|
|
||||||
} else {
|
|
||||||
const events = sortBy(e => -e.created_at, repository.query(filters))
|
const events = sortBy(e => -e.created_at, repository.query(filters))
|
||||||
const since = events[50]!.created_at
|
|
||||||
|
|
||||||
promises.push(pull({relays: dumb, filters: filters.map(assoc("since", since))}))
|
if (events.length > 100) {
|
||||||
|
filters = filters.map(assoc('since', events[100]!.created_at))
|
||||||
|
}
|
||||||
|
|
||||||
|
promises.push(pull({relays: dumb, filters}))
|
||||||
}
|
}
|
||||||
|
|
||||||
return Promise.all(promises)
|
return Promise.all(promises)
|
||||||
|
|
@ -326,11 +324,8 @@ export const {
|
||||||
getKey: channel => channel.id,
|
getKey: channel => channel.id,
|
||||||
load: (id: string, request: Partial<SubscribeRequestWithHandlers> = {}) => {
|
load: (id: string, request: Partial<SubscribeRequestWithHandlers> = {}) => {
|
||||||
const [url, room] = splitChannelId(id)
|
const [url, room] = splitChannelId(id)
|
||||||
const channel = get(channelsById).get(id)
|
|
||||||
const timestamps = channel?.messages.map(m => m.event.created_at) || []
|
|
||||||
const since = Math.max(0, max(timestamps) - 3600)
|
|
||||||
|
|
||||||
return load({...request, relays: [url], filters: [{"#~": [room], since}]})
|
return load({...request, relays: [url], filters: [{"#~": [room]}]})
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,12 +25,10 @@
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
const filter = {kinds: [WRAP], "#p": [$pubkey!]}
|
const filter = {kinds: [WRAP], "#p": [$pubkey!]}
|
||||||
const sub = subscribe({filters: [{...filter, since: ago(30)}]})
|
const relays = ctx.app.router.InboxRelays().getUrls()
|
||||||
|
const sub = subscribe({filters: [{...filter, since: ago(30)}], relays})
|
||||||
|
|
||||||
pullConservatively({
|
pullConservatively({filters: [filter], relays})
|
||||||
filters: [filter],
|
|
||||||
relays: ctx.app.router.InboxRelays().getUrls(),
|
|
||||||
})
|
|
||||||
|
|
||||||
return () => sub.close()
|
return () => sub.close()
|
||||||
})
|
})
|
||||||
|
|
@ -68,11 +66,13 @@
|
||||||
<Icon icon="magnifer" />
|
<Icon icon="magnifer" />
|
||||||
<input bind:value={term} class="grow" type="text" />
|
<input bind:value={term} class="grow" type="text" />
|
||||||
</label>
|
</label>
|
||||||
|
{#key $page.params.chat}
|
||||||
<div class="overflow-auto">
|
<div class="overflow-auto">
|
||||||
{#each chats as { id, pubkeys, messages } (id)}
|
{#each chats as { id, pubkeys, messages } (id)}
|
||||||
<ChatItem {id} {pubkeys} {messages} />
|
<ChatItem {id} {pubkeys} {messages} />
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
|
{/key}
|
||||||
</SecondaryNav>
|
</SecondaryNav>
|
||||||
|
|
||||||
<Page>
|
<Page>
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
import {onMount} from "svelte"
|
import {onMount} from "svelte"
|
||||||
import {page} from "$app/stores"
|
import {page} from "$app/stores"
|
||||||
import {derived} from "svelte/store"
|
import {derived} from "svelte/store"
|
||||||
import {sortBy, remove} from "@welshman/lib"
|
import {ctx, sortBy, now, remove} from "@welshman/lib"
|
||||||
import type {TrustedEvent, EventContent} from "@welshman/util"
|
import type {TrustedEvent, EventContent} from "@welshman/util"
|
||||||
import {createEvent, DIRECT_MESSAGE} from "@welshman/util"
|
import {createEvent, DIRECT_MESSAGE} from "@welshman/util"
|
||||||
import {
|
import {
|
||||||
|
|
@ -91,10 +91,8 @@
|
||||||
elements.reverse()
|
elements.reverse()
|
||||||
}
|
}
|
||||||
|
|
||||||
onMount(() => {
|
onMount(async () => {
|
||||||
for (const pk of others) {
|
await Promise.all(others.map(pk => loadInboxRelaySelections(pk)))
|
||||||
loadInboxRelaySelections(pk)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,6 @@
|
||||||
import ChannelMessage from "@app/components/ChannelMessage.svelte"
|
import ChannelMessage from "@app/components/ChannelMessage.svelte"
|
||||||
import ChannelCompose from "@app/components/ChannelCompose.svelte"
|
import ChannelCompose from "@app/components/ChannelCompose.svelte"
|
||||||
import {
|
import {
|
||||||
loadChannel,
|
|
||||||
userMembership,
|
userMembership,
|
||||||
decodeNRelay,
|
decodeNRelay,
|
||||||
makeChannelId,
|
makeChannelId,
|
||||||
|
|
@ -39,8 +38,7 @@
|
||||||
|
|
||||||
const {nrelay, room = GENERAL} = $page.params
|
const {nrelay, room = GENERAL} = $page.params
|
||||||
const url = decodeNRelay(nrelay)
|
const url = decodeNRelay(nrelay)
|
||||||
const id = makeChannelId(url, room)
|
const channel = deriveChannel(makeChannelId(url, room))
|
||||||
const channel = deriveChannel(id)
|
|
||||||
const thunks = writable({} as Record<string, Thunk>)
|
const thunks = writable({} as Record<string, Thunk>)
|
||||||
|
|
||||||
const assertEvent = (e: any) => e as TrustedEvent
|
const assertEvent = (e: any) => e as TrustedEvent
|
||||||
|
|
@ -84,7 +82,6 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
loadChannel(id)
|
|
||||||
subscribe({filters: [{'#~': [room], since: now()}], relays: [url]})
|
subscribe({filters: [{'#~': [room], since: now()}], relays: [url]})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue