mirror of
https://github.com/darksaid98/oxmysql.git
synced 2026-12-01 22:21:51 +00:00
refactor(logger): only enable profiling with debugging
Breaks slow query warnings, but most people just set the number higher once they get warnings anyway. Also fixes some issues: - profile duration formatting and time (sec to ms). - incorrect log query/param index.
This commit is contained in:
1 parent
bdbe86c0f7
commit
45aadf7442
5 files changed
+43
-19
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import { pool, isServerConnected, waitForConnection } from '.';
|
||||
import { parseArguments } from '../utils/parseArguments';
|
||||
import { parseResponse } from '../utils/parseResponse';
|
||||
import { logQuery } from '../logger';
|
||||
import { logQuery, runProfiler } from '../logger';
|
||||
import type { CFXCallback, CFXParameters } from '../types';
|
||||
import type { QueryType } from '../types';
|
||||
import { scheduleTick } from '../utils/scheduleTick';
|
||||
@@ -32,11 +32,18 @@ export const rawQuery = (
|
||||
|
||||
if (!connection) return;
|
||||
|
||||
const hasProfiler = await runProfiler(connection, invokingResource);
|
||||
|
||||
try {
|
||||
const [result] = await connection.query(query, parameters);
|
||||
const [profiler] = <RowDataPacket[]> await connection.query('SELECT SUM(DURATION) AS `duration` FROM INFORMATION_SCHEMA.PROFILING');
|
||||
|
||||
if (profiler[0]?.duration) logQuery(invokingResource, query, parseFloat(profiler[0].duration), parameters);
|
||||
|
||||
if (hasProfiler) {
|
||||
const [profiler] = <RowDataPacket[]>(
|
||||
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);
|
||||
}
|
||||
|
||||
resolve(cb ? parseResponse(type, result) : null);
|
||||
} catch (err) {
|
||||
|
||||
Reference in new issue
Block a user