Skip to content

Commit

Permalink
fix a few bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
dskvr committed Jan 31, 2025
1 parent 09ace9c commit 3e45767
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 23 deletions.
2 changes: 1 addition & 1 deletion apps/gui/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@nostrwatch/gui",
"description": "",
"version": "0.6.46",
"version": "0.6.47",
"license": "MIT",
"keywords": [
"svelte",
Expand Down
9 changes: 4 additions & 5 deletions apps/gui/src/lib/managers/DataRegister.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,20 +175,18 @@ export class DataRegister {

const expiry = this._dataSets.get(key)?.expiry || this._composite.get(key)?.expiry;
if(!expiry) {
//console.log(`isExpired: ${key} has no expiry (always expired)`)
console.log(`isExpired: ${key} has no expiry (always expired)`)
return true;
}

//console.log(`isExpired: ${key} seeded`, this._seeded.get(key))
const timestamp = this._timestamps.get(key);

if(!timestamp) {
//console.log(`isExpired: ${key} has no timestamp (never been ran)`)
console.log(`isExpired: ${key} has no timestamp (never been ran)`)
return true;
}

const expired = Date.now() - timestamp > (expiry as number);
//console.log(`isExpired: cache has expired`, `${Date.now()} - ${timestamp} [${Date.now()-timestamp}]`, `>`,` ${expiry}`, 'evaluates as:', expired)
console.log(`isExpired: cache has expired`, `${Date.now()} - ${timestamp} [${Date.now()-timestamp}]`, `>`,` ${expiry}`, 'evaluates as:', expired)

return Date.now() - timestamp > (expiry as number);
}
Expand Down Expand Up @@ -253,6 +251,7 @@ export class DataRegister {
for (const childKey of composite.keys) {
if (this.busy(childKey)) continue;
const params: any[] = this.extractParams(childKey, paramsMap);
this.localStorageLoadTimestamp(childKey, params)
if(!this.isExpired(childKey)) continue;
this.start(childKey);

Expand Down
5 changes: 2 additions & 3 deletions apps/gui/src/lib/stores/data-register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { get, writable, type Writable } from "svelte/store";
import { doBootstrap } from "$stores/routines";
import { doAggregateCache, isBootstrapped, isSeeded } from "$stores/app";
import { fetchMonitors, fetchMonitorsChecks, fetchNip11s, fetchOperators } from "$lib/fetchers/bootstrap";
import { beginLiveSync, instance, removeStaleChecksFromStore, seedFromCache } from "$utils/lifecycle";
import { beginLiveSync, bindBootstrapEmitters, instance, liveSync, removeStaleChecksFromStore, seedFromCache } from "$utils/lifecycle";
import { publishEventsToMemoryRelay } from "./events-helpers";
import { delay } from "@nostrwatch/utils";
import type { IEvent } from "@nostrwatch/route66/models/Event";
Expand Down Expand Up @@ -86,9 +86,8 @@ export const dataRegisterInit = async () => {
data.register({
key: 'sync:live',
priority: 200,
fn: beginLiveSync
fn: async () => liveSync()
})

//cache: all (bootstrap)
data.register({
key: 'sync:cache',
Expand Down
2 changes: 1 addition & 1 deletion apps/gui/src/lib/stores/events-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const publishEventsToMemoryRelay = async (_events: IEvent[], from?: strin
// if(from) console.log(`Memory Relay: Publishing ${_events.length} events to memory relay from ${from}`, deterministicHash(_events.map(eventKey)), _events);
if(!_events?.length) return;
const key = deterministicHash(_events.map( event => event.id));
if(testingUniques.has(key)) return console.log(`duplicate add!`, testingUniques.size, _events);
if(testingUniques.has(key)) return //console.log(`duplicate add!`, testingUniques.size, _events);
testingUniques.add(key);
queue.add(async () => {
await delay(20);
Expand Down
2 changes: 1 addition & 1 deletion apps/gui/src/lib/stores/nip11s.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export const operatorPubkeys: Readable<string[]> = derived(
result.add(pubkey)
}
}
console.log('operatorPubkeys', Array.from(result))
// console.log('operatorPubkeys', Array.from(result))
return Array.from(result)
}
)
Expand Down
4 changes: 3 additions & 1 deletion apps/gui/src/lib/utils/lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,10 @@ export const bootstrap = async () => {
}
isBootstrapping.set(false)
removeStaleChecksFromStore()
}

export const liveSync = () => {
if(get(isLivesyncing)) return;

const onevents = (events: IEvent[]) => {
for(const event of events){
liveSyncBatcher.add(event);
Expand Down
2 changes: 1 addition & 1 deletion apps/gui/src/routes/operators/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
onMount(async () => {
if (typeof window === 'undefined' || typeof navigator === 'undefined') return;
console.log('OPERATORS: LOADING COMPONENTS')
// console.log('OPERATORS: LOADING COMPONENTS')
await loadComponents().then(setConfig);
// setConfig()
//
Expand Down
19 changes: 9 additions & 10 deletions libraries/route66/src/services/Service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,18 +169,17 @@ export class Service {
let cacheEvents: IEvent[] = [];
cacheEvents = await this.cacheAdapter.REQ(filters);

if(cacheEvents.length){
if(cacheEvents?.length){
StateManager.emit('events', cacheEvents);
if (callbacks?.onevents) {
callbacks.onevents(cacheEvents);
}
if (callbacks?.onevent) {
callbacks.onevent(event);
}

}

if (callbacks?.onevents) {
callbacks.onevents(cacheEvents);
}
if (callbacks?.onevent) {
callbacks.onevent(event);
}

return cacheEvents;
return cacheEvents?.length? cacheEvents: [];
}

async fetchFromWebsocket(args: WebsocketRequestBody, callbacks?: SubscribeHandlers): Promise<IEvent[]> {
Expand Down

0 comments on commit 3e45767

Please sign in to comment.