mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 02:21:13 +00:00
refactor(core): Lint to enforce lazyloading in modules (#16843)
Co-authored-by: Juuso Tapaninen <juuso@n8n.io>
This commit is contained in:
@@ -99,4 +99,12 @@ export default defineConfig(
|
||||
'n8n-local-rules/no-uncaught-json-parse': 'warn',
|
||||
},
|
||||
},
|
||||
{
|
||||
files: ['**/*.module.ts'],
|
||||
|
||||
rules: {
|
||||
'n8n-local-rules/no-top-level-relative-imports-in-backend-module': 'error',
|
||||
'n8n-local-rules/no-constructor-in-backend-module': 'error',
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
@@ -1,23 +1,16 @@
|
||||
import type { ModuleInterface } from '@n8n/decorators';
|
||||
import { BackendModule } from '@n8n/decorators';
|
||||
import { Container } from '@n8n/di';
|
||||
import './insights.controller';
|
||||
import { InstanceSettings } from 'n8n-core';
|
||||
|
||||
import { InsightsByPeriod } from './database/entities/insights-by-period';
|
||||
import { InsightsMetadata } from './database/entities/insights-metadata';
|
||||
import { InsightsRaw } from './database/entities/insights-raw';
|
||||
|
||||
@BackendModule({ name: 'insights' })
|
||||
export class InsightsModule implements ModuleInterface {
|
||||
async init() {
|
||||
const { instanceType } = Container.get(InstanceSettings);
|
||||
|
||||
/**
|
||||
* Only main- and webhook-type instances collect insights because
|
||||
* only they are informed of finished workflow executions.
|
||||
*/
|
||||
if (instanceType === 'worker') return;
|
||||
if (Container.get(InstanceSettings).instanceType === 'worker') return;
|
||||
|
||||
await import('./insights.controller');
|
||||
|
||||
@@ -25,12 +18,17 @@ export class InsightsModule implements ModuleInterface {
|
||||
Container.get(InsightsService).startTimers();
|
||||
}
|
||||
|
||||
entities() {
|
||||
async entities() {
|
||||
const { InsightsByPeriod } = await import('./database/entities/insights-by-period');
|
||||
const { InsightsMetadata } = await import('./database/entities/insights-metadata');
|
||||
const { InsightsRaw } = await import('./database/entities/insights-raw');
|
||||
|
||||
return [InsightsByPeriod, InsightsMetadata, InsightsRaw];
|
||||
}
|
||||
|
||||
async settings() {
|
||||
const { InsightsService } = await import('./insights.service');
|
||||
|
||||
return Container.get(InsightsService).settings();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user