From 5e1af603b7e18be4a4c67a5ef8f2d3edc13200a5 Mon Sep 17 00:00:00 2001 From: Kieran Date: Thu, 22 Feb 2024 11:46:53 +0000 Subject: [PATCH] refactor: preload with follow list --- packages/shared/package.json | 2 +- packages/shared/src/feed-cache.ts | 2 +- packages/system-react/package.json | 6 +++--- packages/system-web/package.json | 6 +++--- packages/system/package.json | 4 ++-- packages/system/src/index.ts | 3 ++- packages/system/src/nostr-system.ts | 12 ++++++------ 7 files changed, 18 insertions(+), 17 deletions(-) diff --git a/packages/shared/package.json b/packages/shared/package.json index 5933c217..0e1538d1 100644 --- a/packages/shared/package.json +++ b/packages/shared/package.json @@ -1,6 +1,6 @@ { "name": "@snort/shared", - "version": "1.0.13", + "version": "1.0.14", "description": "Shared components for Snort", "type": "module", "module": "src/index.ts", diff --git a/packages/shared/src/feed-cache.ts b/packages/shared/src/feed-cache.ts index 69b595dc..2b84d103 100644 --- a/packages/shared/src/feed-cache.ts +++ b/packages/shared/src/feed-cache.ts @@ -15,7 +15,7 @@ export interface CacheEvents { } export type CachedTable = { - preload(): Promise; + preload(follows?: Array): Promise; keysOnTable(): Array; getFromCache(key?: string): T | undefined; get(key?: string): Promise; diff --git a/packages/system-react/package.json b/packages/system-react/package.json index 95bf67db..2ae13a27 100644 --- a/packages/system-react/package.json +++ b/packages/system-react/package.json @@ -1,6 +1,6 @@ { "name": "@snort/system-react", - "version": "1.2.10", + "version": "1.2.11", "description": "React hooks for @snort/system", "main": "dist/index.js", "module": "src/index.ts", @@ -16,8 +16,8 @@ "dist" ], "dependencies": { - "@snort/shared": "^1.0.13", - "@snort/system": "^1.2.10", + "@snort/shared": "^1.0.14", + "@snort/system": "^1.2.11", "react": "^18.2.0" }, "devDependencies": { diff --git a/packages/system-web/package.json b/packages/system-web/package.json index 69703f8d..13da665a 100644 --- a/packages/system-web/package.json +++ b/packages/system-web/package.json @@ -1,6 +1,6 @@ { "name": "@snort/system-web", - "version": "1.2.10", + "version": "1.2.11", "description": "Web based components @snort/system", "type": "module", "main": "dist/index.js", @@ -16,8 +16,8 @@ "dist" ], "dependencies": { - "@snort/shared": "^1.0.13", - "@snort/system": "^1.2.10", + "@snort/shared": "^1.0.14", + "@snort/system": "^1.2.11", "dexie": "^3.2.4" }, "devDependencies": { diff --git a/packages/system/package.json b/packages/system/package.json index 53dc4f1e..32c0a17a 100644 --- a/packages/system/package.json +++ b/packages/system/package.json @@ -1,6 +1,6 @@ { "name": "@snort/system", - "version": "1.2.10", + "version": "1.2.11", "description": "Snort nostr system package", "type": "module", "main": "dist/index.js", @@ -36,7 +36,7 @@ "@noble/curves": "^1.2.0", "@noble/hashes": "^1.3.2", "@scure/base": "^1.1.2", - "@snort/shared": "^1.0.13", + "@snort/shared": "^1.0.14", "@stablelib/xchacha20": "^1.0.1", "debug": "^4.3.4", "eventemitter3": "^5.0.1", diff --git a/packages/system/src/index.ts b/packages/system/src/index.ts index 7e49ffe8..8a37ee9f 100644 --- a/packages/system/src/index.ts +++ b/packages/system/src/index.ts @@ -68,8 +68,9 @@ export interface SystemInterface { /** * Do some initialization + * @param follows A follower list to preload content for */ - Init(): Promise; + Init(follows?: Array): Promise; /** * Get an active query by ID diff --git a/packages/system/src/nostr-system.ts b/packages/system/src/nostr-system.ts index 2c8ded85..46408948 100644 --- a/packages/system/src/nostr-system.ts +++ b/packages/system/src/nostr-system.ts @@ -269,13 +269,13 @@ export class NostrSystem extends EventEmitter implements Syst this.#queryManager.on("request", (subId: string, f: BuiltRawReqFilter) => this.emit("request", subId, f)); } - async Init() { + async Init(follows?: Array) { const t = [ - this.relayCache.preload(), - this.profileCache.preload(), - this.relayMetricsCache.preload(), - this.eventsCache.preload(), - this.userFollowsCache.preload(), + this.relayCache.preload(follows), + this.profileCache.preload(follows), + this.relayMetricsCache.preload(follows), + this.eventsCache.preload(follows), + this.userFollowsCache.preload(follows), ]; await Promise.all(t); await this.PreloadSocialGraph();