diff options
author | zeripath <art27@cantab.net> | 2020-09-02 22:10:35 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-02 17:10:35 -0400 |
commit | 5fd9f72104aab3136133ec5b058bd67cb39cf314 (patch) | |
tree | ffdf73c3305fdcb9e3ed4430dc96910762cb0e78 /vendor/gitea.com/macaron/session/mysql/mysql.go | |
parent | ed81a95a84bf4da55c49b76a2708d0cc94be3ad6 (diff) | |
download | gitea-5fd9f72104aab3136133ec5b058bd67cb39cf314.tar.gz gitea-5fd9f72104aab3136133ec5b058bd67cb39cf314.zip |
When reading expired sessions - expire them (#12686)
* When reading expired sessions - expire them
Update to latest macaron/session following merge of
https://gitea.com/macaron/session/pulls/11
Also remove old memory provider as 11 updates the memory provider to
make it unnecessary.
Signed-off-by: Andrew Thornton <art27@cantab.net>
* and macaron/session/pulls/12
Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'vendor/gitea.com/macaron/session/mysql/mysql.go')
-rw-r--r-- | vendor/gitea.com/macaron/session/mysql/mysql.go | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/vendor/gitea.com/macaron/session/mysql/mysql.go b/vendor/gitea.com/macaron/session/mysql/mysql.go index da5079b24a..af1cd9dd1b 100644 --- a/vendor/gitea.com/macaron/session/mysql/mysql.go +++ b/vendor/gitea.com/macaron/session/mysql/mysql.go @@ -120,18 +120,20 @@ func (p *MysqlProvider) Init(expire int64, connStr string) (err error) { // Read returns raw session store by session ID. func (p *MysqlProvider) Read(sid string) (session.RawStore, error) { + now := time.Now().Unix() var data []byte - err := p.c.QueryRow("SELECT data FROM session WHERE `key`=?", sid).Scan(&data) + expiry := now + err := p.c.QueryRow("SELECT data, expiry FROM session WHERE `key`=?", sid).Scan(&data, &expiry) if err == sql.ErrNoRows { _, err = p.c.Exec("INSERT INTO session(`key`,data,expiry) VALUES(?,?,?)", - sid, "", time.Now().Unix()) + sid, "", now) } if err != nil { return nil, err } var kv map[interface{}]interface{} - if len(data) == 0 { + if len(data) == 0 || expiry+p.expire <= now { kv = make(map[interface{}]interface{}) } else { kv, err = session.DecodeGob(data) |