Fix url parsing, improve loading from cache

This commit is contained in:
Jon Staab 2024-02-12 12:31:28 -08:00
parent 45174f8dab
commit 5f19ad00f6
7 changed files with 30 additions and 36 deletions

View File

@ -1,8 +1,10 @@
<script lang="ts">
import {onMount} from "svelte"
import {Storage} from "hurdak"
import {uniq} from 'ramda'
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"
@ -44,7 +46,7 @@
selection = getRelaysFromFilters(compileFilters([filter]))
}
return selection
return uniq(selection.concat(LOCAL_RELAY_URL))
}
const loadMore = () => feed.load(5)

View File

@ -12,6 +12,16 @@
hidden = true
}
const getUrlWithHash = () => {
let url = value.url
if (value.hash) {
url += `#${value.hash}`
}
return url
}
let hidden = false
</script>
@ -33,7 +43,7 @@
modal
stopPropagation
class="overflow-hidden text-ellipsis whitespace-nowrap underline"
href={router.at("relays").of(value.url).toString()}>
href={router.at("relays").of(getUrlWithHash()).toString()}>
{displayUrl(value.url)}
</Anchor>
{:else}
@ -41,7 +51,7 @@
external
stopPropagation
class="overflow-hidden text-ellipsis whitespace-nowrap underline"
href={value.url}>
href={getUrlWithHash()}>
{displayUrl(value.url)}
</Anchor>
{/if}

View File

@ -2,7 +2,7 @@
import {onMount} from "svelte"
import {now} from "paravel"
import {whereEq, assocPath, without} from "ramda"
import {noteKinds} from "src/util/nostr"
import {noteKinds, LOCAL_RELAY_URL} from "src/util/nostr"
import {getKey} from "src/util/router"
import {themeBackgroundGradient} from "src/partials/state"
import FlexColumn from "src/partials/FlexColumn.svelte"
@ -145,7 +145,7 @@
shouldListen
hideControls
filter={{kinds: without([30402], noteKinds), "#a": [address]}}
{relays} />
relays={address.startsWith("35834:") ? [LOCAL_RELAY_URL] : relays} />
{:else if activeTab === "calendar"}
<Calendar group={address} filters={[{kinds: [31923], "#a": [address]}]} {relays} />
{:else if activeTab === "market"}

View File

@ -4,7 +4,6 @@ import {now} from "paravel"
import {race} from "src/util/misc"
import {info} from "src/util/logger"
import {
LOCAL_RELAY_URL,
getIdOrAddress,
getIdAndAddress,
noteKinds,
@ -46,8 +45,7 @@ export class FeedLoader {
reposts = new Map<string, Event[]>()
replies = new Map<string, Event[]>()
deferred: Event[] = []
remoteCursor: MultiCursor
localCursor: MultiCursor
cursor: MultiCursor
ready: Promise<void>
isEventMuted = isEventMuted.get()
isDeleted = isDeleted.get()
@ -79,7 +77,7 @@ export class FeedLoader {
])
}
this.remoteCursor = new MultiCursor({
this.cursor = new MultiCursor({
relays: opts.relays,
filters: opts.filters,
onEvent: batch(100, events => {
@ -89,21 +87,9 @@ export class FeedLoader {
}),
})
this.localCursor = new MultiCursor({
relays: [LOCAL_RELAY_URL],
filters: opts.filters,
onEvent: batch(100, events => {
if (opts.shouldLoadParents) {
this.loadParents(this.discardEvents(events))
}
}),
})
const remoteSubs = this.remoteCursor.load(50)
const localSubs = this.localCursor.load(50)
const remoteSubs = this.cursor.load(50)
this.addSubs(remoteSubs)
this.addSubs(localSubs)
// Wait until a good number of subscriptions have completed to reduce the chance of
// out of order notes
@ -270,7 +256,7 @@ export class FeedLoader {
async load(n) {
await this.ready
if (this.remoteCursor.done()) {
if (this.cursor.done()) {
return
}
@ -279,7 +265,7 @@ export class FeedLoader {
relays: this.opts.relays,
})
const [subs, events] = this.remoteCursor.take(n)
const [subs, events] = this.cursor.take(n)
this.addSubs(subs)
@ -290,15 +276,6 @@ export class FeedLoader {
ok = doPipe(ok.concat(this.deferred.splice(0)), [this.deferOrphans, this.deferAncient])
}
// If we have nothing load something from the cache to keep the user happy
if (ok.length === 0) {
const [subs, events] = this.localCursor.take(1)
this.addSubs(subs)
ok = this.discardEvents(events)
}
this.addToFeed(ok)
}

View File

@ -88,7 +88,7 @@ export const getReplyFilters = (events, filter) => {
}
export const getFilterGenerality = filter => {
if (filter.ids || filter["#e"]) {
if (filter.ids || filter["#e"] || filter['#a']) {
return 0
}

View File

@ -5,7 +5,12 @@ let lock = Promise.resolve()
export const getExtension = () => (window as {nostr?: any}).nostr
export const withExtension = (f: (ext: any) => void) => {
lock = lock.then(() => f(getExtension())).catch(e => logger.error(e))
lock = lock.then(() => f(getExtension())).catch(e => {
// Hide a weird error
if (!e.toString().match(/Malformed UTF-8/)) {
logger.error(e)
}
})
return lock
}

View File

@ -17,7 +17,7 @@ export const NOSTR_NPROFILE = "nostr:nprofile"
export const NOSTR_NADDR = "nostr:naddr"
export const urlIsMedia = (url: string) =>
!url.match(/\.(apk|docx|xlsx|csv|dmg)/) && last(url.split("://"))?.includes("/")
!url.match(/\.(apk|docx|xlsx|csv|dmg)/) && last(url.replace(/\/$/, '').split("://"))?.includes("/")
export const parseContent = (event: {content: string; tags?: string[][]}) => {
const result: any[] = []