From 4e70ca6fd0232a0dc5104c1923a3a1f47b3a5c05 Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Thu, 16 Sep 2021 17:36:06 +0100 Subject: [PATCH] Server: Exclude certain queries from slow log --- packages/server/src/db.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/server/src/db.ts b/packages/server/src/db.ts index 8fed626d9..f8ba55898 100644 --- a/packages/server/src/db.ts +++ b/packages/server/src/db.ts @@ -122,8 +122,16 @@ export function setupSlowQueryLog(connection: DbConnection, slowQueryLogMinDurat const queryInfos: Record = {}; + // These queries do not return a response, so "query-response" is not + // called. + const ignoredQueries = /^BEGIN|SAVEPOINT|RELEASE SAVEPOINT|COMMIT|ROLLBACK/gi; + connection.on('query', (data) => { - const timeoutId = makeSlowQueryHandler(slowQueryLogMinDuration, connection, data.sql, data.bindings); + const sql: string = data.sql; + + if (!sql || sql.match(ignoredQueries)) return; + + const timeoutId = makeSlowQueryHandler(slowQueryLogMinDuration, connection, sql, data.bindings); queryInfos[data.__knexQueryUid] = { timeoutId,