set busy timeout, don't add querycontext to SQLiteConn{}, pass through ExecerContext
This commit is contained in:
parent
c962fcf02c
commit
7fddb10d57
|
@ -26,6 +26,7 @@ import (
|
||||||
|
|
||||||
pgx "github.com/jackc/pgx/v5/stdlib"
|
pgx "github.com/jackc/pgx/v5/stdlib"
|
||||||
"github.com/ncruces/go-sqlite3"
|
"github.com/ncruces/go-sqlite3"
|
||||||
|
"github.com/superseriousbusiness/gotosocial/internal/config"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/db"
|
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/db/sqlite"
|
"github.com/superseriousbusiness/gotosocial/internal/db/sqlite"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
|
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
|
||||||
|
@ -43,8 +44,7 @@ var (
|
||||||
// global SQLite3 driver instance.
|
// global SQLite3 driver instance.
|
||||||
sqliteDriver = &sqlite.Driver{
|
sqliteDriver = &sqlite.Driver{
|
||||||
Init: func(c *sqlite3.Conn) error {
|
Init: func(c *sqlite3.Conn) error {
|
||||||
// unset an busy handler.
|
return c.BusyTimeout(config.GetDbSqliteBusyTimeout())
|
||||||
return c.BusyHandler(nil)
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -234,40 +234,12 @@ func (c *SQLiteConn) Exec(query string, args []driver.Value) (driver.Result, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *SQLiteConn) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (res driver.Result, err error) {
|
func (c *SQLiteConn) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (res driver.Result, err error) {
|
||||||
st, err := c.PrepareContext(ctx, query)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
stmt := st.(*SQLiteStmt)
|
|
||||||
res, err = stmt.ExecContext(ctx, args)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *SQLiteConn) Query(query string, args []driver.Value) (driver.Rows, error) {
|
|
||||||
return c.QueryContext(context.Background(), query, toNamedValues(args))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *SQLiteConn) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (rows driver.Rows, err error) {
|
|
||||||
st, err := c.PrepareContext(ctx, query)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
stmt := st.(*SQLiteStmt)
|
|
||||||
err = retryOnBusy(ctx, func() error {
|
err = retryOnBusy(ctx, func() error {
|
||||||
rows, err = stmt.StmtIface.QueryContext(ctx, args)
|
res, err = c.ConnIface.ExecContext(ctx, query, args)
|
||||||
err = processSQLiteError(err)
|
err = processSQLiteError(err)
|
||||||
return err
|
return err
|
||||||
})
|
})
|
||||||
if err != nil {
|
return
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &SQLiteTmpStmtRows{
|
|
||||||
SQLiteRows: SQLiteRows{
|
|
||||||
Ctx: ctx,
|
|
||||||
RowsIface: rows.(sqlite.RowsIface),
|
|
||||||
},
|
|
||||||
SQLiteStmt: stmt,
|
|
||||||
}, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *SQLiteConn) Close() (err error) {
|
func (c *SQLiteConn) Close() (err error) {
|
||||||
|
@ -383,17 +355,6 @@ func (r *SQLiteRows) Close() (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
type SQLiteTmpStmtRows struct {
|
|
||||||
SQLiteRows
|
|
||||||
*SQLiteStmt
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *SQLiteTmpStmtRows) Close() (err error) {
|
|
||||||
err = r.SQLiteRows.Close()
|
|
||||||
_ = r.SQLiteStmt.Close()
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
type conn interface {
|
type conn interface {
|
||||||
driver.Conn
|
driver.Conn
|
||||||
driver.ConnPrepareContext
|
driver.ConnPrepareContext
|
||||||
|
|
|
@ -35,12 +35,7 @@ type ConnIface interface {
|
||||||
driver.Conn
|
driver.Conn
|
||||||
driver.ConnBeginTx
|
driver.ConnBeginTx
|
||||||
driver.ConnPrepareContext
|
driver.ConnPrepareContext
|
||||||
|
driver.ExecerContext
|
||||||
// we hide ExecerContex
|
|
||||||
// as it follows a weird
|
|
||||||
// logic path in sql.DB,
|
|
||||||
// being only a short-path
|
|
||||||
// for stmts with no args.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// StmtIface is the driver.Stmt interface
|
// StmtIface is the driver.Stmt interface
|
||||||
|
|
Loading…
Reference in New Issue