From e198a9722def99788dfe02f13e199aae22835d74 Mon Sep 17 00:00:00 2001 From: Michael Taylor Date: Mon, 7 Oct 2024 10:44:58 -0400 Subject: [PATCH 1/4] feat: additional caching measure to optimize requests --- src/DigNetwork/PropagationServer.ts | 2 +- src/blockchain/DataStore.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/DigNetwork/PropagationServer.ts b/src/DigNetwork/PropagationServer.ts index 6b81407..eba0df2 100644 --- a/src/DigNetwork/PropagationServer.ts +++ b/src/DigNetwork/PropagationServer.ts @@ -146,7 +146,7 @@ export class PropagationServer { const response = await axios.post(url, data, config); console.log( green(`✔ Successfully pinged peer: ${this.ipAddress}`), - response + response.data ); return response.data; } catch (error: any) { diff --git a/src/blockchain/DataStore.ts b/src/blockchain/DataStore.ts index 665d1ec..72f2690 100644 --- a/src/blockchain/DataStore.ts +++ b/src/blockchain/DataStore.ts @@ -41,6 +41,7 @@ import { StoreMonitorRegistry } from "./StoreMonitorRegistry"; // Initialize the cache with a TTL of 180 seconds (3 minutes) const rootHistoryCache = new NodeCache({ stdTTL: 180 }); +const allStoresCache = new NodeCache({ stdTTL: 15 }); const stat = promisify(fs.stat); const readdir = promisify(fs.readdir); From ac112ee12531dd609e97289890562c99af7805c3 Mon Sep 17 00:00:00 2001 From: Michael Taylor Date: Mon, 7 Oct 2024 10:45:36 -0400 Subject: [PATCH 2/4] chore(release): 0.0.1-alpha.157 --- CHANGELOG.md | 7 +++++++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a7c09c1..c956ee8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +### [0.0.1-alpha.157](https://github.com/DIG-Network/dig-chia-sdk/compare/v0.0.1-alpha.156...v0.0.1-alpha.157) (2024-10-07) + + +### Features + +* additional caching measure to optimize requests ([e198a97](https://github.com/DIG-Network/dig-chia-sdk/commit/e198a9722def99788dfe02f13e199aae22835d74)) + ### [0.0.1-alpha.156](https://github.com/DIG-Network/dig-chia-sdk/compare/v0.0.1-alpha.155...v0.0.1-alpha.156) (2024-10-07) diff --git a/package-lock.json b/package-lock.json index ad37fad..4eb193c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@dignetwork/dig-sdk", - "version": "0.0.1-alpha.156", + "version": "0.0.1-alpha.157", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@dignetwork/dig-sdk", - "version": "0.0.1-alpha.156", + "version": "0.0.1-alpha.157", "license": "ISC", "dependencies": { "@dignetwork/datalayer-driver": "^0.1.29", diff --git a/package.json b/package.json index e8f889c..b337947 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@dignetwork/dig-sdk", - "version": "0.0.1-alpha.156", + "version": "0.0.1-alpha.157", "description": "", "type": "commonjs", "main": "./dist/index.js", From 1e501c939b60eea08d9b157c287e80b860c8a89d Mon Sep 17 00:00:00 2001 From: Michael Taylor Date: Mon, 7 Oct 2024 10:49:17 -0400 Subject: [PATCH 3/4] feat: additional caching measure to optimize requests --- src/DigNetwork/PropagationServer.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/DigNetwork/PropagationServer.ts b/src/DigNetwork/PropagationServer.ts index eba0df2..1e47da3 100644 --- a/src/DigNetwork/PropagationServer.ts +++ b/src/DigNetwork/PropagationServer.ts @@ -24,6 +24,7 @@ import NodeCache from "node-cache"; // Initialize cache with a TTL of 1 week (604800 seconds) const storeExistsCache = new NodeCache({ stdTTL: 86400 }); +const pingUpdatecache = new NodeCache({ stdTTL: 86400 }); // Helper function to trim long filenames with ellipsis and ensure consistent padding function formatFilename(filename: string | undefined, maxLength = 30): string { @@ -119,9 +120,17 @@ export class PropagationServer { /** * Ping the current peer about an update to the store, passing rootHash. + * If the combination of ipAddress-storeId-rootHash is cached as "successfully synced", skip the request. * @param rootHash - The root hash for the store update. */ async pingUpdate(rootHash: string): Promise { + const cacheKey = `${this.ipAddress}-${this.storeId}-${rootHash}`; + + // Check if response for this combination is already cached + if (pingUpdatecache.get(cacheKey) === "successfully synced") { + return; + } + try { const httpsAgent = this.createHttpsAgent(); const url = `https://${formatHost(this.ipAddress)}:${ @@ -135,7 +144,6 @@ export class PropagationServer { }, }; - // Data to send in the request (storeId and rootHash) const data = { storeId: this.storeId, rootHash: rootHash, @@ -148,6 +156,12 @@ export class PropagationServer { green(`✔ Successfully pinged peer: ${this.ipAddress}`), response.data ); + + if (response.data.message === "Already Synced") { + // Cache the response as "successfully synced" to avoid redundant requests + pingUpdatecache.set(cacheKey, "successfully synced"); + } + return response.data; } catch (error: any) { console.error(red(`✖ Failed to ping peer: ${this.ipAddress}`)); From 05e917c820e62fe8d5cd92efa6680da6a52615a5 Mon Sep 17 00:00:00 2001 From: Michael Taylor Date: Mon, 7 Oct 2024 10:50:49 -0400 Subject: [PATCH 4/4] chore(release): 0.0.1-alpha.158 --- CHANGELOG.md | 7 +++++++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c956ee8..6b1ecfe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +### [0.0.1-alpha.158](https://github.com/DIG-Network/dig-chia-sdk/compare/v0.0.1-alpha.157...v0.0.1-alpha.158) (2024-10-07) + + +### Features + +* additional caching measure to optimize requests ([1e501c9](https://github.com/DIG-Network/dig-chia-sdk/commit/1e501c939b60eea08d9b157c287e80b860c8a89d)) + ### [0.0.1-alpha.157](https://github.com/DIG-Network/dig-chia-sdk/compare/v0.0.1-alpha.156...v0.0.1-alpha.157) (2024-10-07) diff --git a/package-lock.json b/package-lock.json index 4eb193c..febd10c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@dignetwork/dig-sdk", - "version": "0.0.1-alpha.157", + "version": "0.0.1-alpha.158", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@dignetwork/dig-sdk", - "version": "0.0.1-alpha.157", + "version": "0.0.1-alpha.158", "license": "ISC", "dependencies": { "@dignetwork/datalayer-driver": "^0.1.29", diff --git a/package.json b/package.json index b337947..c2de038 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@dignetwork/dig-sdk", - "version": "0.0.1-alpha.157", + "version": "0.0.1-alpha.158", "description": "", "type": "commonjs", "main": "./dist/index.js",