Skip to content

Commit

Permalink
dbconn: add too verbose debug logs waitQueryToFinish
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivansete-status committed Sep 27, 2024
1 parent 5ccec21 commit 2cea2aa
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions waku/common/databases/db_postgres/dbconn.nim
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,12 @@ proc sendQueryPrepared(
return ok()

proc waitQueryToFinish(
db: DbConn, rowCallback: DataProc = nil
db: DbConn, rowCallback: DataProc = nil, requestId: string
): Future[Result[void, string]] {.async.} =
## The 'rowCallback' param is != nil when the underlying query wants to retrieve results (SELECT.)
## For other queries, like "INSERT", 'rowCallback' should be nil.

debug "waitQueryToFinish", requestId
var dataAvailable = false
proc onDataAvailable(udata: pointer) {.gcsafe, raises: [].} =
dataAvailable = true
Expand All @@ -141,8 +142,10 @@ proc waitQueryToFinish(
asyncengine.addReader2(asyncFd, onDataAvailable).isOkOr:
return err("failed to add event reader in waitQueryToFinish: " & $error)

debug "waitQueryToFinish", requestId
while not dataAvailable:
await sleepAsync(timer.milliseconds(1))
debug "waitQueryToFinish", requestId

## Now retrieve the result
while true:
Expand All @@ -152,6 +155,8 @@ proc waitQueryToFinish(
db.check().isOkOr:
return err("error in query: " & $error)

debug "waitQueryToFinish", requestId

return ok() # reached the end of the results

if not rowCallback.isNil():
Expand Down Expand Up @@ -182,7 +187,7 @@ proc dbConnQuery*(

queryStartTime = getTime().toUnixFloat()

(await db.waitQueryToFinish(rowCallback)).isOkOr:
(await db.waitQueryToFinish(rowCallback, requestId)).isOkOr:
return err("error in dbConnQuery calling waitQueryToFinish: " & $error)

let waitDuration = getTime().toUnixFloat() - queryStartTime
Expand Down Expand Up @@ -218,7 +223,7 @@ proc dbConnQueryPrepared*(

queryStartTime = getTime().toUnixFloat()

(await db.waitQueryToFinish(rowCallback)).isOkOr:
(await db.waitQueryToFinish(rowCallback, requestId)).isOkOr:
return err("error in dbConnQueryPrepared calling waitQueryToFinish: " & $error)

let waitDuration = getTime().toUnixFloat() - queryStartTime
Expand Down

0 comments on commit 2cea2aa

Please sign in to comment.