Skip to content

Commit 27637c1

Browse files
committed
Change when sync is sent during pipelining
1 parent 7f06bc0 commit 27637c1

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

packages/pg/lib/query.js

+12-5
Original file line numberDiff line numberDiff line change
@@ -101,19 +101,22 @@ class Query extends EventEmitter {
101101
this._checkForMultirow()
102102
this._result.addCommandComplete(msg)
103103
// need to sync after each command complete of a prepared statement
104-
this.maybeSync(connection)
104+
// if we were using a row count which results in multiple calls to _getRows
105+
if (this.rows) {
106+
this.maybeSync(connection)
107+
}
105108
}
106109

107110
// if a named prepared statement is created with empty query text
108111
// the backend will send an emptyQuery message but *not* a command complete message
109112
// execution on the connection will hang until the backend receives a sync message
110113
handleEmptyQuery(connection) {
111-
this.maybeSync(connection)
114+
// this.maybeSync(connection)
112115
}
113116

114117
handleError(err, connection) {
115118
// need to sync after error during a prepared statement
116-
this.maybeSync(connection)
119+
// this.maybeSync(connection)
117120
if (this._canceledDueToError) {
118121
err = this._canceledDueToError
119122
this._canceledDueToError = false
@@ -143,7 +146,7 @@ class Query extends EventEmitter {
143146
// say "Therefore, an Execute phase is always terminated by the appearance of exactly one of these messages:
144147
// CommandComplete, EmptyQueryResponse (if the portal was created from an empty query string), ErrorResponse, or PortalSuspended."
145148
maybeSync(connection) {
146-
if (this.isPreparedStatement && !this._hasSentSync) {
149+
if (this.isPreparedStatement) {
147150
this._hasSentSync = true
148151
connection.sync()
149152
}
@@ -181,7 +184,11 @@ class Query extends EventEmitter {
181184
portal: this.portal,
182185
rows: rows,
183186
})
184-
connection.flush()
187+
if (!rows) {
188+
this.maybeSync(connection)
189+
} else {
190+
connection.flush()
191+
}
185192
}
186193

187194
// http://developer.postgresql.org/pgdocs/postgres/protocol-flow.html#PROTOCOL-FLOW-EXT-QUERY

0 commit comments

Comments
 (0)