From f6f73de0b0d1f26381e72f4a1d96f808185f3c08 Mon Sep 17 00:00:00 2001 From: Tate Date: Mon, 25 Nov 2024 07:45:21 +0000 Subject: [PATCH] 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,