clean up use of local relay url

This commit is contained in:
Jon Staab 2024-03-28 14:00:34 -07:00
parent 6ebe24970e
commit 19e2ef222f
3 changed files with 12 additions and 16 deletions

View File

@ -8,7 +8,6 @@
import DayGrid from "@event-calendar/day-grid"
import Interaction from "@event-calendar/interaction"
import {secondsToDate} from "src/util/misc"
import {LOCAL_RELAY_URL} from "src/util/nostr"
import {themeColors} from "src/partials/state"
import Anchor from "src/partials/Anchor.svelte"
import {router} from "src/app/router"
@ -50,7 +49,7 @@
onMount(() => {
const sub = subscribe({
filters,
relays: forcePlatformRelays(getRelaysFromFilters(filters)).concat(LOCAL_RELAY_URL),
relays: forcePlatformRelays(getRelaysFromFilters(filters)),
onEvent: batch(300, chunk => {
events.update($events => {
for (const e of chunk) {

View File

@ -4,7 +4,6 @@
import {writable, readable} from "@coracle.social/lib"
import {FeedLoader} from "src/engine"
import {createScroller} from "src/util/misc"
import {LOCAL_RELAY_URL} from "src/util/nostr"
import {fly} from "src/util/transition"
import {getModal} from "src/partials/state"
import Spinner from "src/partials/Spinner.svelte"
@ -51,9 +50,6 @@
result = forcePlatformRelays(result)
}
if (!skipCache) {
result.push(LOCAL_RELAY_URL)
}
return result
}
@ -67,6 +63,7 @@
filters: compileFilters([filter], {includeReposts: true}),
relays: getRelays(),
anchor,
skipCache,
shouldListen,
shouldDefer: !eager,
shouldLoadParents: true,

View File

@ -1,5 +1,5 @@
import {partition, concat, prop, uniqBy, identity, without, assoc} from "ramda"
import {ensurePlural, doPipe, batch} from "hurdak"
import {doPipe, batch} from "hurdak"
import {now, writable} from "@coracle.social/lib"
import type {Filter} from "@coracle.social/util"
import {
@ -24,6 +24,7 @@ export type FeedOpts = {
filters: Filter[]
onEvent?: (e: Event) => void
anchor?: string
skipCache?: boolean
shouldDefer?: boolean
shouldListen?: boolean
shouldBuffer?: boolean
@ -47,15 +48,13 @@ export class FeedLoader {
isDeleted = isDeleted.get()
constructor(readonly opts: FeedOpts) {
const urls = getUrls(opts.relays)
const filters = ensurePlural(opts.filters)
// No point in subscribing if we have an end date
if (opts.shouldListen && !filters.some(prop("until"))) {
this.addSubs([
subscribe({
relays: urls,
relays: opts.relays,
filters: opts.filters.map(assoc("since", this.since)),
skipCache: opts.skipCache,
onEvent: batch(300, (events: Event[]) => {
events = this.discardEvents(events)
@ -73,9 +72,10 @@ export class FeedLoader {
])
}
this.cursor = new MultiCursor({
relays: opts.relays,
filters: opts.filters,
relays: opts.skipCache ? opts.relays : opts.relays.concat(LOCAL_RELAY_URL),
onEvent: batch(100, events => {
if (opts.shouldLoadParents) {
this.loadParents(this.discardEvents(events))
@ -83,9 +83,7 @@ export class FeedLoader {
}),
})
const remoteSubs = this.cursor.load(50)
this.addSubs(remoteSubs)
const remoteSubs = this.addSubs(this.cursor.load(50))
// Wait until a good number of subscriptions have completed to reduce the chance of
// out of order notes
@ -147,13 +145,15 @@ export class FeedLoader {
// Control
addSubs(subs) {
for (const sub of ensurePlural(subs)) {
for (const sub of subs) {
this.subs.push(sub)
sub.emitter.on("complete", () => {
this.subs = without([sub], this.subs)
})
}
return subs
}
stop() {