Fix channel loading

This commit is contained in:
Jon Staab
2024-10-17 09:44:06 -07:00
parent 8ce79193d1
commit 1055a6d567
6 changed files with 27 additions and 37 deletions
+3 -3
View File
@@ -83,9 +83,9 @@
</p>
</div>
{/if}
<div class="flex w-full gap-2">
<div class="flex w-full gap-3">
{#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}
<div class="w-10 min-w-10 max-w-10" />
{/if}
@@ -100,7 +100,7 @@
<div class="text-sm">
<Content {event} />
{#if thunk}
<div class="badge">
<div class="badge badge-neutral">
<ThunkStatus {thunk} />
</div>
{/if}
+1 -1
View File
@@ -85,7 +85,7 @@
<Avatar
src={$profile?.picture}
class="border border-solid border-base-content"
size={10} />
size={8} />
</Button>
{/if}
<div class="-mt-1 flex-grow pr-1">
+9 -14
View File
@@ -163,18 +163,16 @@ export const pullConservatively = ({relays, filters}: AppSyncOpts) => {
const [smart, dumb] = partition(hasNegentropy, relays)
const promises = [pull({relays: smart, filters})]
// Since pulling from relays without negentropy is expensive, only do it 30% of the time,
// unless we have very few matching events. If that's the case, either we haven't synced
// this filter yet, or there are few enough events that we don't really need to worry about
// 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 {
// Since pulling from relays without negentropy is expensive, limit how many
// duplicates we repeatedly download
if (dumb.length > 0) {
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)
@@ -326,11 +324,8 @@ export const {
getKey: channel => channel.id,
load: (id: string, request: Partial<SubscribeRequestWithHandlers> = {}) => {
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]}]})
},
})