don't use timeout context on close
This commit is contained in:
parent
b23d91e9b1
commit
c987d50f24
|
@ -22,7 +22,6 @@ package sqlite
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql/driver"
|
"database/sql/driver"
|
||||||
"time"
|
|
||||||
|
|
||||||
"modernc.org/sqlite"
|
"modernc.org/sqlite"
|
||||||
|
|
||||||
|
@ -96,17 +95,9 @@ func (c *sqliteConn) QueryContext(ctx context.Context, query string, args []driv
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *sqliteConn) Close() (err error) {
|
func (c *sqliteConn) Close() (err error) {
|
||||||
ctx := context.Background()
|
|
||||||
|
|
||||||
// Set a timeout context to limit execution time.
|
|
||||||
ctx, cncl := context.WithTimeout(ctx, 5*time.Second)
|
|
||||||
|
|
||||||
// see: https://www.sqlite.org/pragma.html#pragma_optimize
|
// see: https://www.sqlite.org/pragma.html#pragma_optimize
|
||||||
const onClose = "PRAGMA analysis_limit=1000; PRAGMA optimize;"
|
const onClose = "PRAGMA analysis_limit=1000; PRAGMA optimize;"
|
||||||
_, _ = c.connIface.ExecContext(ctx, onClose, nil)
|
_, _ = c.connIface.ExecContext(context.Background(), onClose, nil)
|
||||||
|
|
||||||
// Done.
|
|
||||||
cncl()
|
|
||||||
|
|
||||||
// Finally, close the conn.
|
// Finally, close the conn.
|
||||||
err = c.connIface.Close()
|
err = c.connIface.Close()
|
||||||
|
|
|
@ -22,7 +22,6 @@ package sqlite
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql/driver"
|
"database/sql/driver"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/db"
|
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||||
|
|
||||||
|
@ -110,23 +109,13 @@ func (c *sqliteConn) ExecContext(ctx context.Context, query string, args []drive
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *sqliteConn) Close() (err error) {
|
func (c *sqliteConn) Close() (err error) {
|
||||||
ctx := context.Background()
|
|
||||||
|
|
||||||
// Get acces the underlying raw sqlite3 conn.
|
// Get acces the underlying raw sqlite3 conn.
|
||||||
raw := c.connIface.(sqlite3.DriverConn).Raw()
|
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)
|
|
||||||
|
|
||||||
// see: https://www.sqlite.org/pragma.html#pragma_optimize
|
// see: https://www.sqlite.org/pragma.html#pragma_optimize
|
||||||
const onClose = "PRAGMA analysis_limit=1000; PRAGMA optimize;"
|
const onClose = "PRAGMA analysis_limit=1000; PRAGMA optimize;"
|
||||||
_ = raw.Exec(onClose)
|
_ = raw.Exec(onClose)
|
||||||
|
|
||||||
// Unset timeout context.
|
|
||||||
_ = raw.SetInterrupt(old)
|
|
||||||
cncl()
|
|
||||||
|
|
||||||
// Finally, close.
|
// Finally, close.
|
||||||
err = raw.Close()
|
err = raw.Close()
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue