-
Notifications
You must be signed in to change notification settings - Fork 407
#RI-3751-add command execution time #1347
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0a6e199
090efb6
9667a0a
7755c51
dab3a3e
b13a451
414afb7
8aaec4a
7f3fd29
9280bb9
ac7bb16
dea8ff2
d3fa3dc
8991889
2b940de
e1ad246
b504ff4
f2236f2
f6a2fac
04149fd
f1808ac
61a29e7
3956428
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { MigrationInterface, QueryRunner } from "typeorm"; | ||
|
||
export class workbenchExecutionTime1667368983699 implements MigrationInterface { | ||
name = 'workbenchExecutionTime1667368983699' | ||
|
||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(`DROP INDEX "IDX_5cd90dd6def1fd7c521e53fb2c"`); | ||
await queryRunner.query(`CREATE TABLE "temporary_command_execution" ("id" varchar PRIMARY KEY NOT NULL, "databaseId" varchar NOT NULL, "command" text NOT NULL, "result" text NOT NULL, "role" varchar, "nodeOptions" varchar, "encryption" varchar, "createdAt" datetime NOT NULL DEFAULT (datetime('now')), "mode" varchar, "resultsMode" varchar, "summary" varchar, "executionTime" integer, CONSTRAINT "FK_ea8adfe9aceceb79212142206b8" FOREIGN KEY ("databaseId") REFERENCES "database_instance" ("id") ON DELETE CASCADE ON UPDATE NO ACTION)`); | ||
await queryRunner.query(`INSERT INTO "temporary_command_execution"("id", "databaseId", "command", "result", "role", "nodeOptions", "encryption", "createdAt", "mode", "resultsMode", "summary") SELECT "id", "databaseId", "command", "result", "role", "nodeOptions", "encryption", "createdAt", "mode", "resultsMode", "summary" FROM "command_execution"`); | ||
await queryRunner.query(`DROP TABLE "command_execution"`); | ||
await queryRunner.query(`ALTER TABLE "temporary_command_execution" RENAME TO "command_execution"`); | ||
await queryRunner.query(`CREATE INDEX "IDX_5cd90dd6def1fd7c521e53fb2c" ON "command_execution" ("createdAt") `); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(`DROP INDEX "IDX_5cd90dd6def1fd7c521e53fb2c"`); | ||
await queryRunner.query(`ALTER TABLE "command_execution" RENAME TO "temporary_command_execution"`); | ||
await queryRunner.query(`CREATE TABLE "command_execution" ("id" varchar PRIMARY KEY NOT NULL, "databaseId" varchar NOT NULL, "command" text NOT NULL, "result" text NOT NULL, "role" varchar, "nodeOptions" varchar, "encryption" varchar, "createdAt" datetime NOT NULL DEFAULT (datetime('now')), "mode" varchar, "resultsMode" varchar, "summary" varchar, CONSTRAINT "FK_ea8adfe9aceceb79212142206b8" FOREIGN KEY ("databaseId") REFERENCES "database_instance" ("id") ON DELETE CASCADE ON UPDATE NO ACTION)`); | ||
await queryRunner.query(`INSERT INTO "command_execution"("id", "databaseId", "command", "result", "role", "nodeOptions", "encryption", "createdAt", "mode", "resultsMode", "summary") SELECT "id", "databaseId", "command", "result", "role", "nodeOptions", "encryption", "createdAt", "mode", "resultsMode", "summary" FROM "temporary_command_execution"`); | ||
await queryRunner.query(`DROP TABLE "temporary_command_execution"`); | ||
await queryRunner.query(`CREATE INDEX "IDX_5cd90dd6def1fd7c521e53fb2c" ON "command_execution" ("createdAt") `); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,7 +46,10 @@ export class WorkbenchService { | |
}, | ||
]; | ||
} else { | ||
const startCommandExecutionTime = process.hrtime.bigint(); | ||
commandExecution.result = await this.commandsExecutor.sendCommand(clientOptions, { ...dto, command }); | ||
const endCommandExecutionTime = process.hrtime.bigint(); | ||
commandExecution.executionTime = Math.round((Number(endCommandExecutionTime - startCommandExecutionTime) / 1000)); | ||
} | ||
|
||
return commandExecution; | ||
|
@@ -67,6 +70,9 @@ export class WorkbenchService { | |
...dto, | ||
databaseId: clientOptions.instanceId, | ||
}; | ||
let executionTimeInNanoseconds = BigInt(0); | ||
|
||
const startCommandExecutionTime = process.hrtime.bigint(); | ||
|
||
const executionResults = await Promise.all(commands.map(async (singleCommand) => { | ||
const command = multilineCommandToOneLine(singleCommand); | ||
|
@@ -79,9 +85,16 @@ export class WorkbenchService { | |
}); | ||
} | ||
const result = await this.commandsExecutor.sendCommand(clientOptions, { ...dto, command }); | ||
const endCommandExecutionTime = process.hrtime.bigint(); | ||
|
||
executionTimeInNanoseconds += (endCommandExecutionTime - startCommandExecutionTime); | ||
return ({ ...result[0], command }); | ||
})); | ||
|
||
if (Number(executionTimeInNanoseconds) !== 0) { | ||
commandExecution.executionTime = Math.round(Number(executionTimeInNanoseconds) / 1000); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure that using |
||
const successCommands = executionResults.filter( | ||
(command) => command.status === CommandExecutionStatus.Success, | ||
); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
toMatchObject
nice! didn't know this useful feature :)