From 45a0ef444535fff829a5dc107f097d66be0b720b Mon Sep 17 00:00:00 2001 From: Kieran Date: Thu, 6 Jul 2023 00:08:17 +0100 Subject: [PATCH] Add missing function --- packages/system-react/package.json | 4 ++-- packages/system/package.json | 2 +- packages/system/src/nostr-system.ts | 22 ++++++++++++++++++---- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/packages/system-react/package.json b/packages/system-react/package.json index 8e68cb08..679f917d 100644 --- a/packages/system-react/package.json +++ b/packages/system-react/package.json @@ -1,6 +1,6 @@ { "name": "@snort/system-react", - "version": "1.0.9", + "version": "1.0.10", "description": "React hooks for @snort/system", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -16,7 +16,7 @@ "dist" ], "dependencies": { - "@snort/system": "^1.0.14", + "@snort/system": "^1.0.15", "@snort/shared": "^1.0.4", "react": "^18.2.0" } diff --git a/packages/system/package.json b/packages/system/package.json index d41e3837..606da2d1 100644 --- a/packages/system/package.json +++ b/packages/system/package.json @@ -1,6 +1,6 @@ { "name": "@snort/system", - "version": "1.0.14", + "version": "1.0.15", "description": "Snort nostr system package", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/packages/system/src/nostr-system.ts b/packages/system/src/nostr-system.ts index 61486cae..5e4a8596 100644 --- a/packages/system/src/nostr-system.ts +++ b/packages/system/src/nostr-system.ts @@ -4,7 +4,6 @@ import { unwrap, sanitizeRelayUrl, ExternalStore, FeedCache } from "@snort/share import { NostrEvent, TaggedRawEvent } from "./nostr"; import { AuthHandler, Connection, RelaySettings, ConnectionStateSnapshot } from "./connection"; import { Query } from "./query"; -import { RelayCache } from "./gossip-model"; import { NoteStore } from "./note-collection"; import { BuiltRawReqFilter, RequestBuilder } from "./request-builder"; import { RelayMetricHandler } from "./relay-metric-handler"; @@ -16,7 +15,9 @@ import { SystemSnapshot, UserProfileCache, UserRelaysCache, - RelayMetricCache + RelayMetricCache, + db, + UsersRelays } from "."; /** @@ -43,7 +44,7 @@ export class NostrSystem extends ExternalStore implements System /** * Storage class for user relay lists */ - #relayCache: RelayCache; + #relayCache: FeedCache; /** * Storage class for user profiles @@ -67,7 +68,7 @@ export class NostrSystem extends ExternalStore implements System constructor(props: { authHandler?: AuthHandler, - relayCache?: RelayCache, + relayCache?: FeedCache, profileCache?: FeedCache relayMetrics?: FeedCache }) { @@ -93,6 +94,19 @@ export class NostrSystem extends ExternalStore implements System return [...this.#sockets.values()].map(a => a.snapshot()); } + /** + * Setup caches + */ + async Init() { + db.ready = await db.isAvailable(); + const t = [ + this.#relayCache.preload(), + this.#profileCache.preload(), + this.#relayMetricsCache.preload() + ]; + await Promise.all(t); + } + /** * Connect to a NOSTR relay if not already connected */