From 670e85136f1e1cba271f2b9043fb399340b99105 Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Fri, 9 Nov 2018 15:33:31 -0600 Subject: [PATCH] Remove Conn.lastActivityTime It was only read in one place and that was an optimization to get the current time. Replaced that usage with time.Now() --- conn.go | 7 +------ query.go | 3 +-- replication.go | 2 -- 3 files changed, 2 insertions(+), 10 deletions(-) diff --git a/conn.go b/conn.go index 50a6ffb0..653c63a9 100644 --- a/conn.go +++ b/conn.go @@ -111,8 +111,7 @@ func (cc *ConnConfig) networkAddress() (network, address string) { // Use ConnPool to manage access to multiple database connections from multiple // goroutines. type Conn struct { - conn net.Conn // the underlying TCP or unix domain socket connection - lastActivityTime time.Time // the last time the connection was used + conn net.Conn // the underlying TCP or unix domain socket connection wbuf []byte pid uint32 // backend pid secretKey uint32 // key to use to send a cancel query message to the server @@ -307,7 +306,6 @@ func (c *Conn) connect(config ConnConfig, network, address string, tlsConfig *tl c.RuntimeParams = make(map[string]string) c.preparedStatements = make(map[string]*PreparedStatement) c.channels = make(map[string]struct{}) - c.lastActivityTime = time.Now() c.cancelQueryCompleted = make(chan struct{}) close(c.cancelQueryCompleted) c.doneChan = make(chan struct{}) @@ -1423,8 +1421,6 @@ func (c *Conn) rxMsg() (pgproto3.BackendMessage, error) { return nil, err } - c.lastActivityTime = time.Now() - // fmt.Printf("rxMsg: %#v\n", msg) return msg, nil @@ -1742,7 +1738,6 @@ func (c *Conn) ExecEx(ctx context.Context, sql string, options *QueryExOptions, defer c.unlock() startTime := time.Now() - c.lastActivityTime = startTime commandTag, err := c.execEx(ctx, sql, options, arguments...) if err != nil { diff --git a/query.go b/query.go index c014cacd..ef99b1e5 100644 --- a/query.go +++ b/query.go @@ -342,7 +342,7 @@ func (c *Conn) getRows(sql string, args []interface{}) *Rows { c.preallocatedRows = c.preallocatedRows[0 : len(c.preallocatedRows)-1] r.conn = c - r.startTime = c.lastActivityTime + r.startTime = time.Now() r.sql = sql r.args = args @@ -368,7 +368,6 @@ type QueryExOptions struct { } func (c *Conn) QueryEx(ctx context.Context, sql string, options *QueryExOptions, args ...interface{}) (rows *Rows, err error) { - c.lastActivityTime = time.Now() rows = c.getRows(sql, args) err = c.waitForPreviousCancelQuery(ctx) diff --git a/replication.go b/replication.go index 2efdcc79..452f9d3d 100644 --- a/replication.go +++ b/replication.go @@ -330,8 +330,6 @@ func (rc *ReplicationConn) WaitForReplicationMessage(ctx context.Context) (*Repl } func (rc *ReplicationConn) sendReplicationModeQuery(sql string) (*Rows, error) { - rc.c.lastActivityTime = time.Now() - rows := rc.c.getRows(sql, nil) if err := rc.c.lock(); err != nil {