Skip to content

Commit

Permalink
problem: we are making unecessary subscriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
gsovereignty committed Nov 8, 2023
1 parent 5fd03e2 commit 3eacef1
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 325 deletions.
232 changes: 0 additions & 232 deletions src/components/problems/AddProblemModal.svelte

This file was deleted.

13 changes: 8 additions & 5 deletions src/lib/stores/event_sources/relays/livesubscriptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@ import { defaultRelays, rootEventID } from "../../../../settings";
import { unixTimeNow } from "$lib/helpers/mundane";


export function initLiveSubscriptions():[Writable<NDKFilter>, NDKEventStore<ExtendedBaseType<NDKEvent>>] {
export function initLiveSubscriptions():[Writable<NDKFilter>, NDKEventStore<ExtendedBaseType<NDKEvent>> | undefined] {
let _filter:Writable<NDKFilter> = writable({})
let ndk = get(writable(new NDKSvelte({
explicitRelayUrls: defaultRelays,
})))
ndk.connect()
let f:NDKFilter = {ids: [rootEventID]}
let currentsub:NDKEventStore<ExtendedBaseType<NDKEvent>> = ndk.storeSubscribe<NDKEvent>(f, {closeOnEose: true});
//ndk.connect()
//let f:NDKFilter = {ids: [rootEventID]}
let currentsub:NDKEventStore<ExtendedBaseType<NDKEvent>> | undefined = undefined;// = ndk.storeSubscribe<NDKEvent>(f, {closeOnEose: true});
let lastFilter:NDKFilter;
let lastTime = 0;
_filter.subscribe(fi=>{
if (fi != lastFilter || unixTimeNow() > lastTime+60) {
if (!currentsub) {
currentsub = ndk.storeSubscribe<NDKEvent>(fi, {closeOnEose: false})
}
lastFilter = fi
lastTime = unixTimeNow()
resub(currentsub, fi)
Expand All @@ -30,7 +33,7 @@ export function initLiveSubscriptions():[Writable<NDKFilter>, NDKEventStore<Exte
// })
// })
})
setTimeout(()=>{resub(currentsub, lastFilter)}, 2000)
//setTimeout(()=>{resub(currentsub, lastFilter)}, 2000)
return [_filter, currentsub]
}

Expand Down
10 changes: 6 additions & 4 deletions src/lib/stores/nostrocket_state/master_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ export let stateChangeEvents = derived(eligibleForProcessing, ($nis)=>{

allNostrocketEvents.subscribe((e) => {
if (e[0]) {
mempool.update((m)=>{
return m.set(e[0].id,e[0])
})
if (!get(mempool).has(e[0].id)) {
mempool.update((m)=>{
return m.set(e[0].id,e[0])
})
}
}
});

Expand Down Expand Up @@ -238,7 +240,7 @@ let lastConsensusEventAttempt:string = ""
async function init() {
if (!initted) {
initted = true
initProblems(consensusTipState)
//initProblems(consensusTipState)
watchMempool()
}
}
Loading

0 comments on commit 3eacef1

Please sign in to comment.