Skip to content

Commit

Permalink
fix: Display correct query execution time
Browse files Browse the repository at this point in the history
  • Loading branch information
thelindat committed Oct 15, 2021
1 parent bacd9c1 commit 3b55e89
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"connection-string-parser": "^1.0.4",
"github-version-checker": "^2.2.0",
"mysql2": "https://github.com/overextended/node-mysql2.git",
"postinstall-postinstall": "^2.1.0"
"postinstall-postinstall": "^2.1.0"
},
"devDependencies": {
"copy-webpack-plugin": "^9.0.1",
Expand Down
7 changes: 2 additions & 5 deletions src/execute.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,18 @@ import { slowQueryWarning, debug, resourceName } from './config';
const execute = async (query, parameters, resource) => {
ScheduleResourceTick(resourceName);
try {
const time = debug ? process.hrtime.bigint() : Date.now();

[query, parameters] = parseParameters(query, parameters);

const [result] = await pool.query(query, parameters);

const executionTime = debug ? Number(process.hrtime.bigint() - time) / 1e6 : Date.now() - time;
const [rows, _, executionTime] = await pool.query(query, parameters);

if (executionTime >= slowQueryWarning || debug)
console.log(
`^3[${debug ? 'DEBUG' : 'WARNING'}] ${resource} took ${executionTime}ms to execute a query!
${query} ${JSON.stringify(parameters)}^0`
);

return result;
return rows;
} catch (error) {
console.log(
`^1[ERROR] ${resource} was unable to execute a query!
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,7 @@ minimist@^1.2.0:

"mysql2@https://github.com/overextended/node-mysql2.git":
version "2.3.0"
resolved "https://github.com/overextended/node-mysql2.git#694e1003732f048c91a2ab99f7a7667d88a02549"
resolved "https://github.com/overextended/node-mysql2.git#0bd156905d3093d33dddbde10adf1ca8ede18680"
dependencies:
denque "^2.0.1"
generate-function "^2.3.1"
Expand Down

0 comments on commit 3b55e89

Please sign in to comment.