mirror of
https://github.com/darksaid98/oxmysql.git
synced 2026-12-03 06:28:53 +00:00
refactor(logger): add profileBatchStatements
This commit is contained in:
1 parent
51c84a30ca
commit
a8cdc5d1a1
2 files changed
+36
-4
No files matched your search
@@ -1,6 +1,40 @@
|
||||
import { PoolConnection, RowDataPacket } from 'mysql2/promise';
|
||||
import { mysql_debug, mysql_slow_query_warning, mysql_ui } from '../config';
|
||||
import type { CFXParameters } from '../types';
|
||||
|
||||
export const profilerStatements = [
|
||||
'SET profiling_history_size = 0',
|
||||
'SET profiling = 0',
|
||||
'SET profiling_history_size = 100',
|
||||
'SET profiling = 1',
|
||||
];
|
||||
|
||||
export async function profileBatchStatements(
|
||||
connection: PoolConnection,
|
||||
invokingResource: string,
|
||||
query: string | { query: string; params: CFXParameters }[],
|
||||
parameters: CFXParameters | null,
|
||||
offset: number
|
||||
) {
|
||||
const [profiler] = <RowDataPacket[]>(
|
||||
await connection.query('SELECT SUM(DURATION) AS `duration` FROM INFORMATION_SCHEMA.PROFILING GROUP BY QUERY_ID')
|
||||
);
|
||||
|
||||
for (const statement of profilerStatements) await connection.query(statement);
|
||||
|
||||
if (profiler.length === 0) return;
|
||||
|
||||
if (typeof query === 'string' && parameters)
|
||||
for (let i = 0; i < profiler.length; i++) {
|
||||
logQuery(invokingResource, query, parseFloat(profiler[i].duration), parameters[offset]);
|
||||
}
|
||||
else if (typeof query === 'object')
|
||||
for (let i = 0; i < profiler.length; i++) {
|
||||
const transaction = query[offset];
|
||||
logQuery(invokingResource, transaction.query, parseFloat(profiler[i].duration), transaction.params);
|
||||
}
|
||||
}
|
||||
|
||||
interface QueryData {
|
||||
date: number;
|
||||
query: string;
|
||||
|
||||
Reference in new issue
Block a user