mirror of
https://github.com/darksaid98/oxmysql.git
synced 2026-12-02 06:28:54 +00:00
refactor(logger): non-debug query profiling
Use less precise query profiling (script based, rather than sql server based). Re-enables slow query warning, and reduces overhead when ui is enabled.
This commit is contained in:
1 parent
d0683b7f30
commit
e31d84019e
4 files changed
+30
-14
No files matched your search
@@ -1,9 +1,10 @@
|
||||
import { logError, profileBatchStatements, runProfiler } from '../logger';
|
||||
import { logError, logQuery, profileBatchStatements, runProfiler } from '../logger';
|
||||
import { CFXCallback, CFXParameters, QueryType } from '../types';
|
||||
import { parseResponse } from '../utils/parseResponse';
|
||||
import { executeType, parseExecute } from '../utils/parseExecute';
|
||||
import { getPoolConnection } from './connection';
|
||||
import { setCallback } from '../utils/setCallback';
|
||||
import { performance } from 'perf_hooks';
|
||||
|
||||
export const rawExecute = async (
|
||||
invokingResource: string,
|
||||
@@ -44,6 +45,7 @@ export const rawExecute = async (
|
||||
}
|
||||
}
|
||||
|
||||
const startTime = !hasProfiler && performance.now();
|
||||
const [result] = await connection.execute(query, values);
|
||||
|
||||
if (cb) {
|
||||
@@ -56,6 +58,8 @@ export const rawExecute = async (
|
||||
|
||||
if (hasProfiler && ((index > 0 && index % 100 === 0) || index === parametersLength - 1)) {
|
||||
await profileBatchStatements(connection, invokingResource, query, parameters, index < 100 ? 0 : index);
|
||||
} else if (startTime) {
|
||||
logQuery(invokingResource, query, performance.now() - startTime, values);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import type { CFXCallback, CFXParameters } from '../types';
|
||||
import type { QueryType } from '../types';
|
||||
import { getPoolConnection } from './connection';
|
||||
import { RowDataPacket } from 'mysql2';
|
||||
import { performance } from 'perf_hooks';
|
||||
|
||||
export const rawQuery = async (
|
||||
type: QueryType,
|
||||
@@ -28,6 +29,7 @@ export const rawQuery = async (
|
||||
|
||||
try {
|
||||
const hasProfiler = await runProfiler(connection, invokingResource);
|
||||
const startTime = !hasProfiler && performance.now();
|
||||
const [result] = await connection.query(query, parameters);
|
||||
|
||||
if (hasProfiler) {
|
||||
@@ -35,7 +37,9 @@ export const rawQuery = async (
|
||||
await connection.query('SELECT FORMAT(SUM(DURATION) * 1000, 4) AS `duration` FROM INFORMATION_SCHEMA.PROFILING')
|
||||
);
|
||||
|
||||
if (profiler[0]) logQuery(invokingResource, query, profiler[0].duration, parameters);
|
||||
if (profiler[0]) logQuery(invokingResource, query, parseFloat(profiler[0].duration), parameters);
|
||||
} else if (startTime) {
|
||||
logQuery(invokingResource, query, performance.now() - startTime, parameters);
|
||||
}
|
||||
|
||||
if (cb)
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { getPoolConnection } from './connection';
|
||||
import { logError, profileBatchStatements, runProfiler } from '../logger';
|
||||
import { logError, logQuery, profileBatchStatements, runProfiler } from '../logger';
|
||||
import { CFXCallback, CFXParameters, TransactionQuery } from '../types';
|
||||
import { parseTransaction } from '../utils/parseTransaction';
|
||||
import { setCallback } from '../utils/setCallback';
|
||||
import { performance } from 'perf_hooks';
|
||||
|
||||
const transactionError = (queries: { query: string; params?: CFXParameters }[], parameters: CFXParameters) => {
|
||||
`${queries.map((query) => `${query.query} ${JSON.stringify(query.params || [])}`).join('\n')}\n${JSON.stringify(
|
||||
@@ -39,11 +40,13 @@ export const rawTransaction = async (
|
||||
|
||||
for (let i = 0; i < transactionsLength; i++) {
|
||||
const transaction = transactions[i];
|
||||
|
||||
const startTime = !hasProfiler && performance.now();
|
||||
await connection.query(transaction.query, transaction.params);
|
||||
|
||||
if (hasProfiler && ((i > 0 && i % 100 === 0) || i === transactionsLength - 1)) {
|
||||
await profileBatchStatements(connection, invokingResource, transactions, null, i < 100 ? 0 : i);
|
||||
} else if (startTime) {
|
||||
logQuery(invokingResource, transaction.query, performance.now() - startTime, transaction.params);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user