mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2024-06-02 21:39:25 +00:00
use timeout context on close
This commit is contained in:
parent
bb7413ca21
commit
f0d6306011
|
@ -270,10 +270,21 @@ func (c *SQLiteConn) QueryContext(ctx context.Context, query string, args []driv
|
|||
}
|
||||
|
||||
func (c *SQLiteConn) Close() (err error) {
|
||||
ctx := context.Background()
|
||||
|
||||
// Get acces the underlying raw sqlite3 conn.
|
||||
raw := c.ConnIface.(sqlite3.DriverConn).Raw()
|
||||
|
||||
// Set a timeout context to limit execution time.
|
||||
ctx, cncl := context.WithTimeout(ctx, 5*time.Second)
|
||||
old := raw.SetInterrupt(ctx)
|
||||
defer func() { cncl(); raw.SetInterrupt(old) }()
|
||||
|
||||
// see: https://www.sqlite.org/pragma.html#pragma_optimize
|
||||
const onClose = "PRAGMA analysis_limit=1000; PRAGMA optimize;"
|
||||
raw := c.ConnIface.(sqlite3.DriverConn).Raw()
|
||||
_ = raw.Exec(onClose)
|
||||
|
||||
// Finally, release + close.
|
||||
_ = raw.ReleaseMemory()
|
||||
err = raw.Close()
|
||||
return
|
||||
|
|
Loading…
Reference in a new issue