mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-11 04:47:29 -08:00
🐛 Fix performance issue with credentials loading (#2130)
This commit is contained in:
parent
0580bfa69f
commit
128e1b241b
|
@ -261,15 +261,23 @@ export function getCredentialsDataWithParents(type: string): ICredentialsTypeDat
|
||||||
* @param {IWorkflowCredentials} credentials The credentials which have to be able to be resolved
|
* @param {IWorkflowCredentials} credentials The credentials which have to be able to be resolved
|
||||||
* @returns {ICredentialsTypeData}
|
* @returns {ICredentialsTypeData}
|
||||||
*/
|
*/
|
||||||
export function getCredentialsData(credentials: IWorkflowCredentials): ICredentialsTypeData {
|
export function getCredentialsDataByNodes(nodes: INode[]): ICredentialsTypeData {
|
||||||
|
|
||||||
const credentialTypeData: ICredentialsTypeData = {};
|
const credentialTypeData: ICredentialsTypeData = {};
|
||||||
|
|
||||||
for (const credentialType of Object.keys(credentials)) {
|
for (const node of nodes) {
|
||||||
if (credentialTypeData[credentialType] !== undefined) {
|
const credentialsUsedByThisNode = node.credentials;
|
||||||
continue;
|
if (credentialsUsedByThisNode) {
|
||||||
}
|
// const credentialTypesUsedByThisNode = Object.keys(credentialsUsedByThisNode!);
|
||||||
|
for (const credentialType of Object.keys(credentialsUsedByThisNode!)) {
|
||||||
|
if (credentialTypeData[credentialType] !== undefined) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
Object.assign(credentialTypeData, getCredentialsDataWithParents(credentialType));
|
Object.assign(credentialTypeData, getCredentialsDataWithParents(credentialType));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return credentialTypeData;
|
return credentialTypeData;
|
||||||
|
|
|
@ -425,14 +425,41 @@ export class WorkflowRunner {
|
||||||
// Register the active execution
|
// Register the active execution
|
||||||
const executionId = await this.activeExecutions.add(data, subprocess, restartExecutionId);
|
const executionId = await this.activeExecutions.add(data, subprocess, restartExecutionId);
|
||||||
|
|
||||||
// Supply all nodeTypes and credentialTypes
|
// Check if workflow contains a "executeWorkflow" Node as in this
|
||||||
const nodeTypeData = WorkflowHelpers.getAllNodeTypeData() as ITransferNodeTypes;
|
// case we can not know which nodeTypes and credentialTypes will
|
||||||
const credentialTypes = CredentialTypes();
|
// be needed and so have to load all of them in the workflowRunnerProcess
|
||||||
|
let loadAllNodeTypes = false;
|
||||||
|
for (const node of data.workflowData.nodes) {
|
||||||
|
if (node.type === 'n8n-nodes-base.executeWorkflow') {
|
||||||
|
loadAllNodeTypes = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let nodeTypeData: ITransferNodeTypes;
|
||||||
|
let credentialTypeData: ICredentialsTypeData;
|
||||||
|
let credentialsOverwrites = this.credentialsOverwrites;
|
||||||
|
if (loadAllNodeTypes === true) {
|
||||||
|
// Supply all nodeTypes and credentialTypes
|
||||||
|
nodeTypeData = WorkflowHelpers.getAllNodeTypeData();
|
||||||
|
const credentialTypes = CredentialTypes();
|
||||||
|
credentialTypeData = credentialTypes.credentialTypes;
|
||||||
|
} else {
|
||||||
|
// Supply only nodeTypes, credentialTypes and overwrites that the workflow needs
|
||||||
|
nodeTypeData = WorkflowHelpers.getNodeTypeData(data.workflowData.nodes);
|
||||||
|
credentialTypeData = WorkflowHelpers.getCredentialsDataByNodes(data.workflowData.nodes);
|
||||||
|
|
||||||
|
credentialsOverwrites = {};
|
||||||
|
for (const credentialName of Object.keys(credentialTypeData)) {
|
||||||
|
if (this.credentialsOverwrites[credentialName] !== undefined) {
|
||||||
|
credentialsOverwrites[credentialName] = this.credentialsOverwrites[credentialName];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
(data as unknown as IWorkflowExecutionDataProcessWithExecution).executionId = executionId;
|
(data as unknown as IWorkflowExecutionDataProcessWithExecution).executionId = executionId;
|
||||||
(data as unknown as IWorkflowExecutionDataProcessWithExecution).nodeTypeData = nodeTypeData;
|
(data as unknown as IWorkflowExecutionDataProcessWithExecution).nodeTypeData = nodeTypeData;
|
||||||
(data as unknown as IWorkflowExecutionDataProcessWithExecution).credentialsOverwrite = this.credentialsOverwrites;
|
(data as unknown as IWorkflowExecutionDataProcessWithExecution).credentialsOverwrite = this.credentialsOverwrites;
|
||||||
(data as unknown as IWorkflowExecutionDataProcessWithExecution).credentialsTypeData = credentialTypes.credentialTypes;
|
(data as unknown as IWorkflowExecutionDataProcessWithExecution).credentialsTypeData = credentialTypeData;
|
||||||
|
|
||||||
const workflowHooks = WorkflowExecuteAdditionalData.getWorkflowHooksMain(data, executionId);
|
const workflowHooks = WorkflowExecuteAdditionalData.getWorkflowHooksMain(data, executionId);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue