From d528e442ba39f6f4ba77e12c0e09121d998347a8 Mon Sep 17 00:00:00 2001 From: Omar Ajoue Date: Thu, 31 Dec 2020 10:42:16 +0100 Subject: [PATCH 1/4] Run vacuum on sqlite periodically --- packages/cli/commands/start.ts | 13 +++++++++++++ packages/cli/config/index.ts | 8 ++++++++ 2 files changed, 21 insertions(+) diff --git a/packages/cli/commands/start.ts b/packages/cli/commands/start.ts index b6f0a39b3e..52c5cd33dd 100644 --- a/packages/cli/commands/start.ts +++ b/packages/cli/commands/start.ts @@ -12,6 +12,7 @@ import { ActiveWorkflowRunner, CredentialsOverwrites, CredentialTypes, + DatabaseType, Db, ExternalHooks, GenericHelpers, @@ -156,6 +157,18 @@ export class Start extends Command { // Wait till the database is ready await startDbInitPromise; + const dbType = await GenericHelpers.getConfigValue('database.type') as DatabaseType; + + if (dbType === 'sqlite') { + const vacuumInterval = config.get('database.sqlite.vacuumInterval') as number; + if (vacuumInterval >= 0) { + Db.collections.Execution!.query("VACUUM;"); + if (vacuumInterval > 0) { + setInterval(() => Db.collections.Execution!.query("VACUUM;"), vacuumInterval * 1000); + } + } + } + if (flags.tunnel === true) { this.log('\nWaiting for tunnel ...'); diff --git a/packages/cli/config/index.ts b/packages/cli/config/index.ts index 5cbacddf85..f8a348274a 100644 --- a/packages/cli/config/index.ts +++ b/packages/cli/config/index.ts @@ -124,6 +124,14 @@ const config = convict({ env: 'DB_MYSQLDB_USER', }, }, + sqlite: { + vacuumInterval: { + doc: 'SQLite Vacuum operation interval', + format: Number, + default: 86400, // Given in seconds; -1 disables. 0 executes only at startup. + env: 'DB_SQLITE_VACUUM_INTERVAL', + }, + }, }, credentials: { From 04a8912a945441833323f61eaec1ea641184f260 Mon Sep 17 00:00:00 2001 From: Omar Ajoue Date: Mon, 4 Jan 2021 09:30:02 +0100 Subject: [PATCH 2/4] Changed vacuum operation to run on startup only. Also it is now off by default. --- packages/cli/commands/start.ts | 8 +++----- packages/cli/config/index.ts | 10 +++++----- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/packages/cli/commands/start.ts b/packages/cli/commands/start.ts index 52c5cd33dd..409c2b763c 100644 --- a/packages/cli/commands/start.ts +++ b/packages/cli/commands/start.ts @@ -160,12 +160,10 @@ export class Start extends Command { const dbType = await GenericHelpers.getConfigValue('database.type') as DatabaseType; if (dbType === 'sqlite') { - const vacuumInterval = config.get('database.sqlite.vacuumInterval') as number; - if (vacuumInterval >= 0) { + const shouldRunVacuum = config.get('database.sqlite.executeVacuumOnStartup') as number; + if (shouldRunVacuum) { + console.log('ran vacuum'); Db.collections.Execution!.query("VACUUM;"); - if (vacuumInterval > 0) { - setInterval(() => Db.collections.Execution!.query("VACUUM;"), vacuumInterval * 1000); - } } } diff --git a/packages/cli/config/index.ts b/packages/cli/config/index.ts index f8a348274a..05ef88771e 100644 --- a/packages/cli/config/index.ts +++ b/packages/cli/config/index.ts @@ -125,11 +125,11 @@ const config = convict({ }, }, sqlite: { - vacuumInterval: { - doc: 'SQLite Vacuum operation interval', - format: Number, - default: 86400, // Given in seconds; -1 disables. 0 executes only at startup. - env: 'DB_SQLITE_VACUUM_INTERVAL', + executeVacuumOnStartup: { + doc: 'Runs VACUUM operation on startup to rebuild the database. Reduces filesize and optimizes indexes. WARNING: This is a long running blocking operation. Will increase boot time.', + format: Boolean, + default: false, + env: 'DB_SQLITE_VACUUM_ON_STARTUP', }, }, }, From ba8ea6c0f57596380fce47f00a530ba8c1bd9448 Mon Sep 17 00:00:00 2001 From: Omar Ajoue Date: Wed, 6 Jan 2021 13:01:56 +0100 Subject: [PATCH 3/4] Removing console.log message --- packages/cli/commands/start.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/cli/commands/start.ts b/packages/cli/commands/start.ts index 409c2b763c..c40c0e6392 100644 --- a/packages/cli/commands/start.ts +++ b/packages/cli/commands/start.ts @@ -162,7 +162,6 @@ export class Start extends Command { if (dbType === 'sqlite') { const shouldRunVacuum = config.get('database.sqlite.executeVacuumOnStartup') as number; if (shouldRunVacuum) { - console.log('ran vacuum'); Db.collections.Execution!.query("VACUUM;"); } } From 78f81144995920624198265f9f42cd4f7f2f70d9 Mon Sep 17 00:00:00 2001 From: Jan Oberhauser Date: Thu, 7 Jan 2021 13:17:49 +0100 Subject: [PATCH 4/4] :zap: Minor text change --- packages/cli/config/index.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/cli/config/index.ts b/packages/cli/config/index.ts index 05ef88771e..0793e8c7f1 100644 --- a/packages/cli/config/index.ts +++ b/packages/cli/config/index.ts @@ -126,11 +126,11 @@ const config = convict({ }, sqlite: { executeVacuumOnStartup: { - doc: 'Runs VACUUM operation on startup to rebuild the database. Reduces filesize and optimizes indexes. WARNING: This is a long running blocking operation. Will increase boot time.', + doc: 'Runs VACUUM operation on startup to rebuild the database. Reduces filesize and optimizes indexes. WARNING: This is a long running blocking operation. Will increase start-up time.', format: Boolean, default: false, - env: 'DB_SQLITE_VACUUM_ON_STARTUP', - }, + env: 'DB_SQLITE_VACUUM_ON_STARTUP', + }, }, },