Add some limits on subscriptions

This commit is contained in:
Jonathan Staab 2022-11-26 10:43:35 -08:00
parent 4cf0945305
commit 395b34554f
7 changed files with 14 additions and 6 deletions

View File

@ -1,5 +1,6 @@
Bugs
- [ ] Ellipsize and hyperlink links
- [ ] Be sure to deduplicate all events if needed
- [ ] Format text with line breaks - pre, or split/br
- [ ] Remove dexie, or use it instead of localstorage for cached data

View File

@ -20,7 +20,8 @@
onMount(() => {
return findNotes(channels.main, {
since: new Date().valueOf() / 1000 - 7 * 24 * 60 * 60,
since: now() - timedelta(1, 'days'),
limit: 100,
}, $notes => {
notes = $notes
})

View File

@ -22,6 +22,8 @@
return findNotes(channels.main, {
authors: [pubkey],
since: now() - timedelta(1, 'days'),
limit: 100,
}, $notes => {
notes = $notes
})

View File

@ -1,4 +1,5 @@
import {prop, sortBy, uniqBy, find, last, groupBy} from 'ramda'
import {debounce} from 'throttle-debounce'
import {writable, derived, get} from 'svelte/store'
import {switcherFn, ensurePlural} from 'hurdak/lib/hurdak'
import {getLocalJson, setLocalJson, now, timedelta} from "src/util/misc"
@ -101,5 +102,5 @@ export const findNotes = (channel, queries, cb) => {
}
)
return annotatedNotes.subscribe(cb)
return annotatedNotes.subscribe(debounce(300, cb))
}

View File

@ -33,6 +33,7 @@ export const registerRelay = async url => {
db.relays.put({...json, url})
}
registerRelay('wss://nostr-relay-dev.wlvs.space')
registerRelay('wss://nostr-pub.wellorder.net')
registerRelay('wss://nostr-relay.wlvs.space')
registerRelay('ws://localhost:7000')

View File

@ -5,10 +5,12 @@ import {getLocalJson, setLocalJson} from "src/util/misc"
export const nostr = relayPool()
// Initialize nostr channels with a noop query
export const channels = {
main: nostr.sub({filter: {}, cb: noop}),
modal: nostr.sub({filter: {}, cb: noop}),
getter: nostr.sub({filter: {}, cb: noop}),
main: nostr.sub({filter: {ids: []}, cb: noop}),
modal: nostr.sub({filter: {ids: []}, cb: noop}),
getter: nostr.sub({filter: {ids: []}, cb: noop}),
}
// Augment nostr with some extra methods

View File

@ -27,7 +27,7 @@ export const setLocalJson = (k, v) => {
}
}
export const now = () => new Date().valueOf() / 1000
export const now = () => Math.round(new Date().valueOf() / 1000)
export const timedelta = (n, unit = 'seconds') => {
switch (unit) {