Skip to content

Commit

Permalink
Updates httpProvider and wsProvider to reduce memeory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
filvecchiato committed Oct 8, 2024
1 parent 694a6ba commit efba101
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src/Specs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,23 @@ export class Specs {
},
),
);
// Types
this._specs.appendSpec(
MODULES.SUBSTRATE,
this._specs.getSpec(CONFIG.TYPES, 'absolute path to file with `typesSpec` type definitions for @polkadot/api', {
default: '',
mandatory: false,
}),
);

// CACHE_CAPACITY
this._specs.appendSpec(
MODULES.SUBSTRATE,
this._specs.getSpec(CONFIG.CACHE_CAPACITY, 'max cache size for @polkadot/api caching system, 0 bypasses cache', {
default: 0,
mandatory: false,
}),
);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ async function main() {

logger.info(`Version: ${packageJSON.version}`);

const { TYPES_BUNDLE, TYPES_SPEC, TYPES_CHAIN, TYPES } = config.SUBSTRATE;
const { TYPES_BUNDLE, TYPES_SPEC, TYPES_CHAIN, TYPES, CACHE_CAPACITY } = config.SUBSTRATE;
// Instantiate a web socket connection to the node and load types
const api = await ApiPromise.create({
provider: config.SUBSTRATE.URL.startsWith('http')
? new HttpProvider(config.SUBSTRATE.URL, undefined, 0)
: new WsProvider(config.SUBSTRATE.URL, undefined, undefined, undefined, 0),
? new HttpProvider(config.SUBSTRATE.URL, undefined, CACHE_CAPACITY || 0)
: new WsProvider(config.SUBSTRATE.URL, undefined, undefined, undefined, CACHE_CAPACITY || 0),
/* eslint-disable @typescript-eslint/no-var-requires */
typesBundle: TYPES_BUNDLE ? (require(TYPES_BUNDLE) as OverrideBundleType) : (tempTypesBundle as OverrideBundleType),
typesChain: TYPES_CHAIN ? (require(TYPES_CHAIN) as Record<string, RegistryTypes>) : undefined,
Expand Down

0 comments on commit efba101

Please sign in to comment.