Skip to content

Commit

Permalink
storeModelFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
yoozo committed Nov 25, 2024
1 parent 54b02b3 commit f6f73de
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 47 deletions.
13 changes: 2 additions & 11 deletions packages/node-core/src/indexer/core.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand All @@ -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,
Expand Down
12 changes: 12 additions & 0 deletions packages/node-core/src/indexer/storeModelProvider/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}
20 changes: 2 additions & 18 deletions packages/node/src/subcommands/reindex.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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,
Expand Down
20 changes: 2 additions & 18 deletions packages/node/src/subcommands/testing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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,
Expand Down

0 comments on commit f6f73de

Please sign in to comment.