Skip to content

Commit

Permalink
remove vacuuming logic
Browse files Browse the repository at this point in the history
  • Loading branch information
mertalev committed Sep 2, 2024
1 parent 29aa2e7 commit 015298e
Showing 1 changed file with 1 addition and 26 deletions.
27 changes: 1 addition & 26 deletions server/src/repositories/database.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,7 @@ export class DatabaseRepository implements IDatabaseRepository {
}

async runMigrations(options?: { transaction?: 'all' | 'none' | 'each' }): Promise<void> {
const migrations = await this.dataSource.runMigrations(options);
if (migrations.length === 0) {
return;
}

this.logger.debug(`Vacuuming after running migrations`);
await this.vacuum();
await this.dataSource.runMigrations(options);
}

async withLock<R>(lock: DatabaseLock, callback: () => Promise<R>): Promise<R> {
Expand Down Expand Up @@ -245,23 +239,4 @@ export class DatabaseRepository implements IDatabaseRepository {
private async releaseLock(lock: DatabaseLock, queryRunner: QueryRunner): Promise<void> {
return queryRunner.query('SELECT pg_advisory_unlock($1)', [lock]);
}

private async vacuum(table?: string) {
let command = table ? `vacuum analyze ${table};` : 'vacuum analyze;';
try {
await this.dataSource.query(command);
} catch (error: any) {
this.logger.error(`Could not run command '${command}': ${error.message}`);
this.logger.error(`If using Docker Compose, you may wish to add 'shm_size: 512m' to the database service`);

try {
command = table ? `vacuum full ${table};` : 'vacuum full;';
this.logger.error(`Attempting '${command}' instead`);
await this.dataSource.query(command);
} catch (error: any) {
this.logger.error(`Could not run '${command}' (${error.message}). Please ensure you have enough disk space`);
this.logger.error(`For best performance, resolve the error and run the ${command} SQL command manually`);
}
}
}
}

0 comments on commit 015298e

Please sign in to comment.