From 2137ae23d789af765a7555028e9651029f88cadc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=A4=95=E0=A4=BE=E0=A4=B0=E0=A4=A4=E0=A5=8B=E0=A4=AB?= =?UTF-8?q?=E0=A5=8D=E0=A4=AB=E0=A5=87=E0=A4=B2=E0=A4=B8=E0=A5=8D=E0=A4=95?= =?UTF-8?q?=E0=A5=8D=E0=A4=B0=E0=A4=BF=E0=A4=AA=E0=A5=8D=E0=A4=9F=E2=84=A2?= Date: Fri, 24 Feb 2023 18:02:34 +0100 Subject: [PATCH 1/4] fix(core): Fix execution pruning queries (#5562) * fix(core): Execution pruning should delete query should use the `OR` operator * fix(core): Prune executions in a chunk to avoid sqlite error "Expression tree is too large" * reduce the memory usage during execution pruning --- .../cli/src/WorkflowExecuteAdditionalData.ts | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/packages/cli/src/WorkflowExecuteAdditionalData.ts b/packages/cli/src/WorkflowExecuteAdditionalData.ts index cf21a80ca4..4488af126c 100644 --- a/packages/cli/src/WorkflowExecuteAdditionalData.ts +++ b/packages/cli/src/WorkflowExecuteAdditionalData.ts @@ -44,7 +44,7 @@ import { import pick from 'lodash.pick'; import type { FindOptionsWhere } from 'typeorm'; -import { LessThanOrEqual } from 'typeorm'; +import { LessThanOrEqual, In } from 'typeorm'; import { DateUtils } from 'typeorm/util/DateUtils'; import config from '@/config'; import * as Db from '@/Db'; @@ -212,7 +212,9 @@ async function pruneExecutionData(this: WorkflowHooks): Promise { // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment const utcDate = DateUtils.mixedDateToUtcDatetimeString(date); - const toPrune: FindOptionsWhere = { stoppedAt: LessThanOrEqual(utcDate) }; + const toPrune: Array> = [ + { stoppedAt: LessThanOrEqual(utcDate) }, + ]; if (maxCount > 0) { const executions = await Db.collections.Execution.find({ @@ -223,27 +225,29 @@ async function pruneExecutionData(this: WorkflowHooks): Promise { }); if (executions[0]) { - toPrune.id = LessThanOrEqual(executions[0].id); + toPrune.push({ id: LessThanOrEqual(executions[0].id) }); } } const isBinaryModeDefaultMode = config.getEnv('binaryDataManager.mode') === 'default'; try { - const executions = isBinaryModeDefaultMode - ? [] - : await Db.collections.Execution.find({ - select: ['id'], - where: toPrune, - }); - await Db.collections.Execution.delete(toPrune); setTimeout(() => { throttling = false; }, timeout * 1000); - // Mark binary data for deletion for all executions - if (!isBinaryModeDefaultMode) - await BinaryDataManager.getInstance().markDataForDeletionByExecutionIds( - executions.map(({ id }) => id), - ); + let executionIds: Array; + do { + executionIds = ( + await Db.collections.Execution.find({ + select: ['id'], + where: toPrune, + take: 100, + }) + ).map(({ id }) => id); + await Db.collections.Execution.delete({ id: In(executionIds) }); + // Mark binary data for deletion for all executions + if (!isBinaryModeDefaultMode) + await BinaryDataManager.getInstance().markDataForDeletionByExecutionIds(executionIds); + } while (executionIds.length > 0); } catch (error) { ErrorReporter.error(error); throttling = false; From 51eedaccd427ec11b12fbf43d9dd3f0ebe9633d2 Mon Sep 17 00:00:00 2001 From: Csaba Tuncsik Date: Mon, 27 Feb 2023 12:25:45 +0100 Subject: [PATCH 2/4] fix(core): Fix Filtering of Workflow by Tags (#5570) --- packages/cli/src/workflows/workflows.services.ts | 2 +- packages/cli/test/integration/shared/testDb.ts | 1 + .../test/integration/workflows.controller.ee.test.ts | 10 ++++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/cli/src/workflows/workflows.services.ts b/packages/cli/src/workflows/workflows.services.ts index 2b736faf15..58a0a56a7b 100644 --- a/packages/cli/src/workflows/workflows.services.ts +++ b/packages/cli/src/workflows/workflows.services.ts @@ -164,7 +164,7 @@ export class WorkflowsService { if (!config.getEnv('workflowTagsDisabled')) { relations.push('tags'); - select.tags = { name: true }; + select.tags = { id: true, name: true }; } if (isSharingEnabled()) { diff --git a/packages/cli/test/integration/shared/testDb.ts b/packages/cli/test/integration/shared/testDb.ts index a0e9dc52f4..4b26eb1625 100644 --- a/packages/cli/test/integration/shared/testDb.ts +++ b/packages/cli/test/integration/shared/testDb.ts @@ -401,6 +401,7 @@ export async function createManyWorkflows( /** * Store a workflow in the DB (without a trigger) and optionally assign it to a user. + * @param attributes workflow attributes * @param user user to assign the workflow to */ export async function createWorkflow(attributes: Partial = {}, user?: User) { diff --git a/packages/cli/test/integration/workflows.controller.ee.test.ts b/packages/cli/test/integration/workflows.controller.ee.test.ts index b03bbebc74..d43e9f790e 100644 --- a/packages/cli/test/integration/workflows.controller.ee.test.ts +++ b/packages/cli/test/integration/workflows.controller.ee.test.ts @@ -154,6 +154,7 @@ describe('GET /workflows', () => { test('should return workflows without nodes, sharing and credential usage details', async () => { const owner = await testDb.createUser({ globalRole: globalOwnerRole }); const member = await testDb.createUser({ globalRole: globalMemberRole }); + const tag = await testDb.createTag({ name: 'test' }); const savedCredential = await saveCredential(randomCredentialPayload(), { user: owner }); @@ -175,6 +176,7 @@ describe('GET /workflows', () => { }, }, ], + tags: [tag], }, owner, ); @@ -193,6 +195,14 @@ describe('GET /workflows', () => { expect(fetchedWorkflow.sharedWith).not.toBeDefined() expect(fetchedWorkflow.usedCredentials).not.toBeDefined() expect(fetchedWorkflow.nodes).not.toBeDefined() + expect(fetchedWorkflow.tags).toEqual( + expect.arrayContaining([ + expect.objectContaining({ + id: expect.any(String), + name: expect.any(String) + }) + ]) + ) }); }); From 43eec66828b2e03418402742c9695e08b1165bdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=A4=95=E0=A4=BE=E0=A4=B0=E0=A4=A4=E0=A5=8B=E0=A4=AB?= =?UTF-8?q?=E0=A5=8D=E0=A4=AB=E0=A5=87=E0=A4=B2=E0=A4=B8=E0=A5=8D=E0=A4=95?= =?UTF-8?q?=E0=A5=8D=E0=A4=B0=E0=A4=BF=E0=A4=AA=E0=A5=8D=E0=A4=9F=E2=84=A2?= Date: Mon, 27 Feb 2023 12:35:59 +0100 Subject: [PATCH 3/4] fix(core): Revert `isPending` check on the user entity (#5571) --- packages/cli/src/databases/entities/User.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/cli/src/databases/entities/User.ts b/packages/cli/src/databases/entities/User.ts index d62bf8482f..6cba438f79 100644 --- a/packages/cli/src/databases/entities/User.ts +++ b/packages/cli/src/databases/entities/User.ts @@ -111,9 +111,6 @@ export class User extends AbstractEntity implements IUser { @AfterLoad() @AfterUpdate() computeIsPending(): void { - this.isPending = - this.globalRole?.name === 'owner' && this.globalRole.scope === 'global' - ? false - : this.password === null; + this.isPending = this.password === null; } } From 948b37592f2efc4b92bad23a235dd908b950d6ef Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 27 Feb 2023 12:42:56 +0100 Subject: [PATCH 4/4] :rocket: Release 0.217.2 (#5573) --- CHANGELOG.md | 11 +++++++++++ package.json | 2 +- packages/cli/package.json | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b7bd29603..38d9c9e343 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,14 @@ +## [0.217.2](https://github.com/n8n-io/n8n/compare/n8n@0.217.1...n8n@0.217.2) (2023-02-27) + + +### Bug Fixes + +* **core:** Fix execution pruning queries ([#5562](https://github.com/n8n-io/n8n/issues/5562)) ([2137ae2](https://github.com/n8n-io/n8n/commit/2137ae23d789af765a7555028e9651029f88cadc)) +* **core:** Fix Filtering of Workflow by Tags ([#5570](https://github.com/n8n-io/n8n/issues/5570)) ([51eedac](https://github.com/n8n-io/n8n/commit/51eedaccd427ec11b12fbf43d9dd3f0ebe9633d2)) +* **core:** Revert `isPending` check on the user entity ([#5571](https://github.com/n8n-io/n8n/issues/5571)) ([43eec66](https://github.com/n8n-io/n8n/commit/43eec66828b2e03418402742c9695e08b1165bdd)) + + + ## [0.217.1](https://github.com/n8n-io/n8n/compare/n8n@0.217.0...n8n@0.217.1) (2023-02-24) diff --git a/package.json b/package.json index 0b205e4a35..0ad9b44fa7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "n8n", - "version": "0.217.1", + "version": "0.217.2", "private": true, "homepage": "https://n8n.io", "engines": { diff --git a/packages/cli/package.json b/packages/cli/package.json index 2cad4b9737..cd4d66f3bb 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -1,6 +1,6 @@ { "name": "n8n", - "version": "0.217.1", + "version": "0.217.2", "description": "n8n Workflow Automation Tool", "license": "SEE LICENSE IN LICENSE.md", "homepage": "https://n8n.io",