@dhedge/backend-flatcoin-core 0.2.93 → 0.2.94

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,7 +4,9 @@ import { MultichainConfig } from '../entity';
4
4
  export declare class MultichainConfigService {
5
5
  private configRepository;
6
6
  private readonly logger;
7
- private baseConfig;
7
+ private readonly configs;
8
8
  constructor(configRepository: MultichainConfigRepository, logger: Logger);
9
- baseConfigs(): Promise<MultichainConfig>;
9
+ loadConfigs(appName: string, blockChainCode: string): Promise<MultichainConfig | undefined>;
10
+ private getConfigFromCache;
11
+ private putConfigsToCache;
10
12
  }
@@ -16,25 +16,34 @@ let MultichainConfigService = class MultichainConfigService {
16
16
  constructor(configRepository, logger) {
17
17
  this.configRepository = configRepository;
18
18
  this.logger = logger;
19
+ this.configs = new Map();
19
20
  }
20
- async baseConfigs() {
21
- if (this.baseConfig) {
22
- return this.baseConfig;
21
+ async loadConfigs(appName, blockChainCode) {
22
+ if (this.getConfigFromCache(appName, blockChainCode)) {
23
+ return this.getConfigFromCache(appName, blockChainCode);
23
24
  }
24
25
  else {
25
- const result = await this.configRepository.getById(1);
26
+ const result = await this.configRepository.getByAppAndCode(appName, blockChainCode);
26
27
  if (!result) {
27
- throw new Error('failed to load multichain config from db');
28
+ throw new Error(`failed to load multichain config from db for ${appName} code ${blockChainCode}`);
28
29
  }
29
30
  else {
30
- if (!this.baseConfig) {
31
- this.baseConfig = result;
32
- this.logger.log(`multichain config loaded from database`);
31
+ if (!this.getConfigFromCache(appName, blockChainCode)) {
32
+ this.putConfigsToCache(appName, blockChainCode, result);
33
+ this.logger.log(`multichain config loaded from database for ${appName} code ${blockChainCode}`);
33
34
  }
34
- return this.baseConfig;
35
+ return this.getConfigFromCache(appName, blockChainCode);
35
36
  }
36
37
  }
37
38
  }
39
+ getConfigFromCache(appName, blockChainCode) {
40
+ const key = appName.concat(blockChainCode);
41
+ return this.configs.get(key);
42
+ }
43
+ putConfigsToCache(appName, blockChainCode, config) {
44
+ const key = appName.concat(blockChainCode);
45
+ this.configs.set(key, config);
46
+ }
38
47
  };
39
48
  exports.MultichainConfigService = MultichainConfigService;
40
49
  exports.MultichainConfigService = MultichainConfigService = __decorate([
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhedge/backend-flatcoin-core",
3
- "version": "0.2.93",
3
+ "version": "0.2.94",
4
4
  "description": "Backend Flatcoin Core",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",