summaryrefslogtreecommitdiff
path: root/vendor/github.com/jackc/pgx/v5/internal
diff options
context:
space:
mode:
authorLibravatar dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>2023-11-06 14:44:53 +0000
committerLibravatar GitHub <noreply@github.com>2023-11-06 14:44:53 +0000
commit9b76afc851090268316fd8890366957632b49a44 (patch)
tree4f1539dd8f831bb22bad9ae21d8ab1d17278b323 /vendor/github.com/jackc/pgx/v5/internal
parent[chore]: Bump github.com/tdewolff/minify/v2 from 2.20.0 to 2.20.6 (#2337) (diff)
downloadgotosocial-9b76afc851090268316fd8890366957632b49a44.tar.xz
[chore]: Bump github.com/jackc/pgx/v5 from 5.4.3 to 5.5.0 (#2336)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Diffstat (limited to 'vendor/github.com/jackc/pgx/v5/internal')
-rw-r--r--vendor/github.com/jackc/pgx/v5/internal/stmtcache/lru_cache.go12
-rw-r--r--vendor/github.com/jackc/pgx/v5/internal/stmtcache/stmtcache.go31
2 files changed, 18 insertions, 25 deletions
diff --git a/vendor/github.com/jackc/pgx/v5/internal/stmtcache/lru_cache.go b/vendor/github.com/jackc/pgx/v5/internal/stmtcache/lru_cache.go
index a25cc8b1c..859345fcb 100644
--- a/vendor/github.com/jackc/pgx/v5/internal/stmtcache/lru_cache.go
+++ b/vendor/github.com/jackc/pgx/v5/internal/stmtcache/lru_cache.go
@@ -34,7 +34,8 @@ func (c *LRUCache) Get(key string) *pgconn.StatementDescription {
}
-// Put stores sd in the cache. Put panics if sd.SQL is "". Put does nothing if sd.SQL already exists in the cache.
+// Put stores sd in the cache. Put panics if sd.SQL is "". Put does nothing if sd.SQL already exists in the cache or
+// sd.SQL has been invalidated and HandleInvalidated has not been called yet.
func (c *LRUCache) Put(sd *pgconn.StatementDescription) {
if sd.SQL == "" {
panic("cannot store statement description with empty SQL")
@@ -44,6 +45,13 @@ func (c *LRUCache) Put(sd *pgconn.StatementDescription) {
return
}
+ // The statement may have been invalidated but not yet handled. Do not readd it to the cache.
+ for _, invalidSD := range c.invalidStmts {
+ if invalidSD.SQL == sd.SQL {
+ return
+ }
+ }
+
if c.l.Len() == c.cap {
c.invalidateOldest()
}
@@ -73,6 +81,8 @@ func (c *LRUCache) InvalidateAll() {
c.l = list.New()
}
+// HandleInvalidated returns a slice of all statement descriptions invalidated since the last call to HandleInvalidated.
+// Typically, the caller will then deallocate them.
func (c *LRUCache) HandleInvalidated() []*pgconn.StatementDescription {
invalidStmts := c.invalidStmts
c.invalidStmts = nil
diff --git a/vendor/github.com/jackc/pgx/v5/internal/stmtcache/stmtcache.go b/vendor/github.com/jackc/pgx/v5/internal/stmtcache/stmtcache.go
index e1bdcba57..b2940e230 100644
--- a/vendor/github.com/jackc/pgx/v5/internal/stmtcache/stmtcache.go
+++ b/vendor/github.com/jackc/pgx/v5/internal/stmtcache/stmtcache.go
@@ -2,18 +2,17 @@
package stmtcache
import (
- "strconv"
- "sync/atomic"
+ "crypto/sha256"
+ "encoding/hex"
"github.com/jackc/pgx/v5/pgconn"
)
-var stmtCounter int64
-
-// NextStatementName returns a statement name that will be unique for the lifetime of the program.
-func NextStatementName() string {
- n := atomic.AddInt64(&stmtCounter, 1)
- return "stmtcache_" + strconv.FormatInt(n, 10)
+// StatementName returns a statement name that will be stable for sql across multiple connections and program
+// executions.
+func StatementName(sql string) string {
+ digest := sha256.Sum256([]byte(sql))
+ return "stmtcache_" + hex.EncodeToString(digest[0:24])
}
// Cache caches statement descriptions.
@@ -39,19 +38,3 @@ type Cache interface {
// Cap returns the maximum number of cached prepared statement descriptions.
Cap() int
}
-
-func IsStatementInvalid(err error) bool {
- pgErr, ok := err.(*pgconn.PgError)
- if !ok {
- return false
- }
-
- // https://github.com/jackc/pgx/issues/1162
- //
- // We used to look for the message "cached plan must not change result type". However, that message can be localized.
- // Unfortunately, error code "0A000" - "FEATURE NOT SUPPORTED" is used for many different errors and the only way to
- // tell the difference is by the message. But all that happens is we clear a statement that we otherwise wouldn't
- // have so it should be safe.
- possibleInvalidCachedPlanError := pgErr.Code == "0A000"
- return possibleInvalidCachedPlanError
-}