Skip to content

Commit a33084f

Browse files
committed
Don't prepare named statements twice
1 parent 11aaf68 commit a33084f

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

Diff for: packages/pg/lib/client.js

+4
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,10 @@ class Client extends EventEmitter {
498498
}
499499
this.blocked = query.blocking
500500
this.sentQueryQueue.push(query)
501+
if (query.name) {
502+
console.log(`we store that ${query.name} has been submitted`)
503+
this.connection.submittedNamedStatements[query.name] = query.text
504+
}
501505
}
502506

503507
if (this.readyForQuery === true) {

Diff for: packages/pg/lib/connection.js

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ class Connection extends EventEmitter {
1919
this._keepAliveInitialDelayMillis = config.keepAliveInitialDelayMillis
2020
this.lastBuffer = false
2121
this.parsedStatements = {}
22+
// to track preparation of statements submitted to server
23+
this.submittedNamedStatements = {}
2224
this.ssl = config.ssl || false
2325
this._ending = false
2426
this._emitMessage = false

Diff for: packages/pg/lib/query.js

+6
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,12 @@ class Query extends EventEmitter {
160160
}
161161

162162
hasBeenParsed(connection) {
163+
if (connection.submittedNamedStatements[this.name]) {
164+
console.log(`-----------------------------------`)
165+
console.log(`query.hasBeenParsed : This statement has already been prepared`)
166+
console.log(`-----------------------------------`)
167+
return true
168+
}
163169
return this.name && connection.parsedStatements[this.name]
164170
}
165171

0 commit comments

Comments
 (0)