Skip to content

Commit

Permalink
pass requestId to dbconn to be printed
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivansete-status committed Sep 27, 2024
1 parent ef47477 commit 5ccec21
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
13 changes: 11 additions & 2 deletions waku/common/databases/db_postgres/dbconn.nim
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,11 @@ proc waitQueryToFinish(
pqclear(pqResult)

proc dbConnQuery*(
db: DbConn, query: SqlQuery, args: seq[string], rowCallback: DataProc
db: DbConn,
query: SqlQuery,
args: seq[string],
rowCallback: DataProc,
requestId: string,
): Future[Result[void, string]] {.async, gcsafe.} =
let cleanedQuery = ($query).replace(" ", "").replace("\n", "")
## remove everything between ' or " all possible sequence of numbers. e.g. rm partition partition
Expand Down Expand Up @@ -188,6 +192,7 @@ proc dbConnQuery*(

if "insert" notin ($query).toLower():
debug "dbConnQuery",
requestId,
query = $query,
querySummary,
waitDurationSecs = waitDuration,
Expand All @@ -202,6 +207,7 @@ proc dbConnQueryPrepared*(
paramLengths: seq[int32],
paramFormats: seq[int32],
rowCallback: DataProc,
requestId: string,
): Future[Result[void, string]] {.async, gcsafe.} =
var queryStartTime = getTime().toUnixFloat()
db.sendQueryPrepared(stmtName, paramValues, paramLengths, paramFormats).isOkOr:
Expand All @@ -222,6 +228,9 @@ proc dbConnQueryPrepared*(

if "insert" notin stmtName.toLower():
debug "dbConnQueryPrepared",
stmtName, waitDurationSecs = waitDuration, sendDurationSecs = sendDuration
requestId,
stmtName,
waitDurationSecs = waitDuration,
sendDurationSecs = sendDuration

return ok()
6 changes: 3 additions & 3 deletions waku/common/databases/db_postgres/pgasyncpool.nim
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ proc releaseConn(pool: PgAsyncPool, conn: DbConn) =
if pool.conns[i].dbConn == conn:
pool.conns[i].busy = false

const SlowQueryThresholdInNanoSeconds = 2_000_000_000
const SlowQueryThresholdInNanoSeconds = 1_000_000_000

proc pgQuery*(
pool: PgAsyncPool,
Expand All @@ -167,7 +167,7 @@ proc pgQuery*(
debug "pgQuery slow query",
query_duration_secs = (queryDuration / 1_000_000_000), query, requestId

(await conn.dbConnQuery(sql(query), args, rowCallback)).isOkOr:
(await conn.dbConnQuery(sql(query), args, rowCallback, requestId)).isOkOr:
return err("error in asyncpool query: " & $error)

return ok()
Expand Down Expand Up @@ -218,7 +218,7 @@ proc runStmt*(

(
await conn.dbConnQueryPrepared(
stmtName, paramValues, paramLengths, paramFormats, rowCallback
stmtName, paramValues, paramLengths, paramFormats, rowCallback, requestId
)
).isOkOr:
return err("error in runStmt: " & $error)
Expand Down

0 comments on commit 5ccec21

Please sign in to comment.