From 54b02b30e46e1d167f5b2758f4baa612b354d581 Mon Sep 17 00:00:00 2001 From: Tate Date: Mon, 25 Nov 2024 07:17:51 +0000 Subject: [PATCH 1/3] fix IStoreModelProvider inject --- packages/node/CHANGELOG.md | 3 +++ .../node/src/subcommands/reindex.module.ts | 23 ++++++++++++++++++- .../node/src/subcommands/testing.module.ts | 23 ++++++++++++++++++- 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/packages/node/CHANGELOG.md b/packages/node/CHANGELOG.md index 593c2076bf..c5cdcdc503 100644 --- a/packages/node/CHANGELOG.md +++ b/packages/node/CHANGELOG.md @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed +- Fix part of the module.ts file that is missing the logic for injecting `IStoreModelProvider`. + ## [5.3.0] - 2024-11-22 ### Added - Support for historical indexing by timestamp as well as block height (#2584) diff --git a/packages/node/src/subcommands/reindex.module.ts b/packages/node/src/subcommands/reindex.module.ts index 965bfef559..9254a21057 100644 --- a/packages/node/src/subcommands/reindex.module.ts +++ b/packages/node/src/subcommands/reindex.module.ts @@ -14,7 +14,10 @@ import { ConnectionPoolService, NodeConfig, ConnectionPoolStateManager, + IStoreModelProvider, + PlainStoreModelService, } from '@subql/node-core'; +import { Sequelize } from '@subql/x-sequelize'; import { ConfigureModule } from '../configure/configure.module'; import { ApiService } from '../indexer/api.service'; import { DsProcessorService } from '../indexer/ds-processor.service'; @@ -23,7 +26,25 @@ import { UnfinalizedBlocksService } from '../indexer/unfinalizedBlocks.service'; @Module({ providers: [ - StoreCacheService, + { + provide: 'IStoreModelProvider', + useFactory: ( + nodeConfig: NodeConfig, + eventEmitter: EventEmitter2, + schedulerRegistry: SchedulerRegistry, + sequelize: Sequelize, + ): IStoreModelProvider => { + return nodeConfig.enableCache + ? new StoreCacheService( + sequelize, + nodeConfig, + eventEmitter, + schedulerRegistry, + ) + : new PlainStoreModelService(sequelize, nodeConfig); + }, + inject: [NodeConfig, EventEmitter2, SchedulerRegistry, Sequelize], + }, StoreService, ReindexService, PoiService, diff --git a/packages/node/src/subcommands/testing.module.ts b/packages/node/src/subcommands/testing.module.ts index 0f6d806e35..63e9dd61da 100644 --- a/packages/node/src/subcommands/testing.module.ts +++ b/packages/node/src/subcommands/testing.module.ts @@ -16,7 +16,10 @@ import { TestRunner, SandboxService, NodeConfig, + IStoreModelProvider, + PlainStoreModelService, } from '@subql/node-core'; +import { Sequelize } from '@subql/x-sequelize'; import { ConfigureModule } from '../configure/configure.module'; import { ApiService } from '../indexer/api.service'; import { DsProcessorService } from '../indexer/ds-processor.service'; @@ -29,7 +32,25 @@ import { UnfinalizedBlocksService } from '../indexer/unfinalizedBlocks.service'; providers: [ InMemoryCacheService, StoreService, - StoreCacheService, + { + provide: 'IStoreModelProvider', + useFactory: ( + nodeConfig: NodeConfig, + eventEmitter: EventEmitter2, + schedulerRegistry: SchedulerRegistry, + sequelize: Sequelize, + ): IStoreModelProvider => { + return nodeConfig.enableCache + ? new StoreCacheService( + sequelize, + nodeConfig, + eventEmitter, + schedulerRegistry, + ) + : new PlainStoreModelService(sequelize, nodeConfig); + }, + inject: [NodeConfig, EventEmitter2, SchedulerRegistry, Sequelize], + }, EventEmitter2, PoiService, PoiSyncService, From f6f73de0b0d1f26381e72f4a1d96f808185f3c08 Mon Sep 17 00:00:00 2001 From: Tate Date: Mon, 25 Nov 2024 07:45:21 +0000 Subject: [PATCH 2/3] storeModelFactory --- packages/node-core/src/indexer/core.module.ts | 13 ++---------- .../src/indexer/storeModelProvider/utils.ts | 12 +++++++++++ .../node/src/subcommands/reindex.module.ts | 20 ++----------------- .../node/src/subcommands/testing.module.ts | 20 ++----------------- 4 files changed, 18 insertions(+), 47 deletions(-) diff --git a/packages/node-core/src/indexer/core.module.ts b/packages/node-core/src/indexer/core.module.ts index 1f4cb87c3f..f5a3cbcb29 100644 --- a/packages/node-core/src/indexer/core.module.ts +++ b/packages/node-core/src/indexer/core.module.ts @@ -15,7 +15,7 @@ import {MonitorService} from './monitor.service'; import {PoiService, PoiSyncService} from './poi'; import {SandboxService} from './sandbox.service'; import {StoreService} from './store.service'; -import {IStoreModelProvider, PlainStoreModelService, StoreCacheService} from './storeModelProvider'; +import {storeModelFactory} from './storeModelProvider'; @Module({ providers: [ @@ -31,16 +31,7 @@ import {IStoreModelProvider, PlainStoreModelService, StoreCacheService} from './ StoreService, { provide: 'IStoreModelProvider', - useFactory: ( - nodeConfig: NodeConfig, - eventEmitter: EventEmitter2, - schedulerRegistry: SchedulerRegistry, - sequelize: Sequelize - ): IStoreModelProvider => { - return nodeConfig.enableCache - ? new StoreCacheService(sequelize, nodeConfig, eventEmitter, schedulerRegistry) - : new PlainStoreModelService(sequelize, nodeConfig); - }, + useFactory: storeModelFactory, inject: [NodeConfig, EventEmitter2, SchedulerRegistry, Sequelize], }, AdminListener, diff --git a/packages/node-core/src/indexer/storeModelProvider/utils.ts b/packages/node-core/src/indexer/storeModelProvider/utils.ts index 0ca72be4cb..81ead9d583 100644 --- a/packages/node-core/src/indexer/storeModelProvider/utils.ts +++ b/packages/node-core/src/indexer/storeModelProvider/utils.ts @@ -2,6 +2,7 @@ // SPDX-License-Identifier: GPL-3.0 import {StoreCacheService} from './storeCache.service'; +import {PlainStoreModelService} from './storeModel.service'; import {IStoreModelProvider} from './types'; export async function cacheProviderFlushData(modelProvider: IStoreModelProvider, forceFlush?: boolean) { @@ -14,3 +15,14 @@ export async function cacheProviderResetData(modelProvider: IStoreModelProvider) await modelProvider.resetData(); } } + +export function storeModelFactory( + nodeConfig: any, + eventEmitter: any, + schedulerRegistry: any, + sequelize: any +): IStoreModelProvider { + return nodeConfig.enableCache + ? new StoreCacheService(sequelize, nodeConfig, eventEmitter, schedulerRegistry) + : new PlainStoreModelService(sequelize, nodeConfig); +} diff --git a/packages/node/src/subcommands/reindex.module.ts b/packages/node/src/subcommands/reindex.module.ts index 9254a21057..6f45c5ad19 100644 --- a/packages/node/src/subcommands/reindex.module.ts +++ b/packages/node/src/subcommands/reindex.module.ts @@ -7,15 +7,13 @@ import { SchedulerRegistry } from '@nestjs/schedule'; import { DbModule, ForceCleanService, - StoreCacheService, ReindexService, StoreService, PoiService, ConnectionPoolService, NodeConfig, ConnectionPoolStateManager, - IStoreModelProvider, - PlainStoreModelService, + storeModelFactory, } from '@subql/node-core'; import { Sequelize } from '@subql/x-sequelize'; import { ConfigureModule } from '../configure/configure.module'; @@ -28,21 +26,7 @@ import { UnfinalizedBlocksService } from '../indexer/unfinalizedBlocks.service'; providers: [ { provide: 'IStoreModelProvider', - useFactory: ( - nodeConfig: NodeConfig, - eventEmitter: EventEmitter2, - schedulerRegistry: SchedulerRegistry, - sequelize: Sequelize, - ): IStoreModelProvider => { - return nodeConfig.enableCache - ? new StoreCacheService( - sequelize, - nodeConfig, - eventEmitter, - schedulerRegistry, - ) - : new PlainStoreModelService(sequelize, nodeConfig); - }, + useFactory: storeModelFactory, inject: [NodeConfig, EventEmitter2, SchedulerRegistry, Sequelize], }, StoreService, diff --git a/packages/node/src/subcommands/testing.module.ts b/packages/node/src/subcommands/testing.module.ts index 63e9dd61da..bbaa0c079f 100644 --- a/packages/node/src/subcommands/testing.module.ts +++ b/packages/node/src/subcommands/testing.module.ts @@ -11,13 +11,11 @@ import { InMemoryCacheService, PoiService, PoiSyncService, - StoreCacheService, StoreService, TestRunner, SandboxService, NodeConfig, - IStoreModelProvider, - PlainStoreModelService, + storeModelFactory, } from '@subql/node-core'; import { Sequelize } from '@subql/x-sequelize'; import { ConfigureModule } from '../configure/configure.module'; @@ -34,21 +32,7 @@ import { UnfinalizedBlocksService } from '../indexer/unfinalizedBlocks.service'; StoreService, { provide: 'IStoreModelProvider', - useFactory: ( - nodeConfig: NodeConfig, - eventEmitter: EventEmitter2, - schedulerRegistry: SchedulerRegistry, - sequelize: Sequelize, - ): IStoreModelProvider => { - return nodeConfig.enableCache - ? new StoreCacheService( - sequelize, - nodeConfig, - eventEmitter, - schedulerRegistry, - ) - : new PlainStoreModelService(sequelize, nodeConfig); - }, + useFactory: storeModelFactory, inject: [NodeConfig, EventEmitter2, SchedulerRegistry, Sequelize], }, EventEmitter2, From c518a751bd514de296e6c9ee7dd9af591eb4c7cf Mon Sep 17 00:00:00 2001 From: Tate Date: Mon, 25 Nov 2024 07:49:31 +0000 Subject: [PATCH 3/3] fix --- .../src/indexer/storeModelProvider/utils.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/node-core/src/indexer/storeModelProvider/utils.ts b/packages/node-core/src/indexer/storeModelProvider/utils.ts index 81ead9d583..8e8782b251 100644 --- a/packages/node-core/src/indexer/storeModelProvider/utils.ts +++ b/packages/node-core/src/indexer/storeModelProvider/utils.ts @@ -1,6 +1,10 @@ // Copyright 2020-2024 SubQuery Pte Ltd authors & contributors // SPDX-License-Identifier: GPL-3.0 +import {EventEmitter2} from '@nestjs/event-emitter'; +import {SchedulerRegistry} from '@nestjs/schedule'; +import {NodeConfig} from '@subql/node-core/configure'; +import {Sequelize} from '@subql/x-sequelize'; import {StoreCacheService} from './storeCache.service'; import {PlainStoreModelService} from './storeModel.service'; import {IStoreModelProvider} from './types'; @@ -17,10 +21,10 @@ export async function cacheProviderResetData(modelProvider: IStoreModelProvider) } export function storeModelFactory( - nodeConfig: any, - eventEmitter: any, - schedulerRegistry: any, - sequelize: any + nodeConfig: NodeConfig, + eventEmitter: EventEmitter2, + schedulerRegistry: SchedulerRegistry, + sequelize: Sequelize ): IStoreModelProvider { return nodeConfig.enableCache ? new StoreCacheService(sequelize, nodeConfig, eventEmitter, schedulerRegistry)