diff --git a/packages/core/server/src/application.ts b/packages/core/server/src/application.ts index d85d98b00..e7c721e7c 100644 --- a/packages/core/server/src/application.ts +++ b/packages/core/server/src/application.ts @@ -5,7 +5,7 @@ import { Cache, createCache, ICacheConfig } from '@nocobase/cache'; import Database, { CollectionOptions, IDatabaseOptions } from '@nocobase/database'; import { AppLoggerOptions, createAppLogger, Logger } from '@nocobase/logger'; import { ResourceOptions, Resourcer } from '@nocobase/resourcer'; -import { applyMixins, AsyncEmitter, Toposort, ToposortOptions } from '@nocobase/utils'; +import { applyMixins, AsyncEmitter, Toposort, ToposortOptions, measureExecutionTime } from '@nocobase/utils'; import chalk from 'chalk'; import { Command, CommandOptions, ParseOptions } from 'commander'; import { IncomingMessage, Server, ServerResponse } from 'http'; @@ -632,18 +632,29 @@ export class Application exten async upgrade(options: any = {}) { await this.emitAsync('beforeUpgrade', this, options); const force = false; - await this.db.migrator.up(); - await this.db.sync({ - force, - alter: { - drop: force, - }, - }); + + await measureExecutionTime(async () => { + await this.db.migrator.up(); + }, 'Migrator'); + + await measureExecutionTime(async () => { + await this.db.sync({ + force, + alter: { + drop: force, + }, + }); + }, 'Sync'); + await this.version.update(); await this.emitAsync('afterUpgrade', this, options); + this.log.debug(chalk.green(`✨ NocoBase has been upgraded to v${this.getVersion()}`)); + if (this._started) { - await this.restart(); + await measureExecutionTime(async () => { + await this.restart(); + }, 'Restart'); } } diff --git a/packages/core/utils/src/index.ts b/packages/core/utils/src/index.ts index f7b6ec638..cdd659c07 100644 --- a/packages/core/utils/src/index.ts +++ b/packages/core/utils/src/index.ts @@ -20,5 +20,6 @@ export * from './requireModule'; export * from './toposort'; export * from './uid'; export * from './url'; +export * from './measure-execution-time'; export { dayjs, lodash }; diff --git a/packages/core/utils/src/measure-execution-time.ts b/packages/core/utils/src/measure-execution-time.ts new file mode 100644 index 000000000..f2e330135 --- /dev/null +++ b/packages/core/utils/src/measure-execution-time.ts @@ -0,0 +1,7 @@ +export async function measureExecutionTime(operation, operationName) { + const startTime = Date.now(); + await operation(); + const endTime = Date.now(); + const duration = (endTime - startTime).toFixed(0); + console.log(`${operationName} completed in ${duration} milliseconds`); +}