Run vacuum on sqlite on startup according to settings (#1290)

* Run vacuum on sqlite periodically

* Changed vacuum operation to run on startup only. Also it is now off by default.

* Removing console.log message
This commit is contained in:
Jan 2021-01-07 13:18:24 +01:00 committed by GitHub
commit 2086ef7cf4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View file

@ -12,6 +12,7 @@ import {
ActiveWorkflowRunner, ActiveWorkflowRunner,
CredentialsOverwrites, CredentialsOverwrites,
CredentialTypes, CredentialTypes,
DatabaseType,
Db, Db,
ExternalHooks, ExternalHooks,
GenericHelpers, GenericHelpers,
@ -156,6 +157,15 @@ export class Start extends Command {
// Wait till the database is ready // Wait till the database is ready
await startDbInitPromise; await startDbInitPromise;
const dbType = await GenericHelpers.getConfigValue('database.type') as DatabaseType;
if (dbType === 'sqlite') {
const shouldRunVacuum = config.get('database.sqlite.executeVacuumOnStartup') as number;
if (shouldRunVacuum) {
Db.collections.Execution!.query("VACUUM;");
}
}
if (flags.tunnel === true) { if (flags.tunnel === true) {
this.log('\nWaiting for tunnel ...'); this.log('\nWaiting for tunnel ...');

View file

@ -124,6 +124,14 @@ const config = convict({
env: 'DB_MYSQLDB_USER', env: 'DB_MYSQLDB_USER',
}, },
}, },
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 start-up time.',
format: Boolean,
default: false,
env: 'DB_SQLITE_VACUUM_ON_STARTUP',
},
},
}, },
credentials: { credentials: {