feat: add measure execution function (#2801)
This commit is contained in:
parent
8bd6ef897c
commit
2dc964d4f1
@ -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<StateT = DefaultState, ContextT = DefaultContext> 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');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,5 +20,6 @@ export * from './requireModule';
|
||||
export * from './toposort';
|
||||
export * from './uid';
|
||||
export * from './url';
|
||||
export * from './measure-execution-time';
|
||||
|
||||
export { dayjs, lodash };
|
||||
|
7
packages/core/utils/src/measure-execution-time.ts
Normal file
7
packages/core/utils/src/measure-execution-time.ts
Normal file
@ -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`);
|
||||
}
|
Loading…
Reference in New Issue
Block a user