don't use timeout context on close

This commit is contained in:
kim 2024-05-05 23:06:43 +01:00
parent b23d91e9b1
commit c987d50f24
2 changed files with 1 additions and 21 deletions

View File

@ -22,7 +22,6 @@ package sqlite
import (
"context"
"database/sql/driver"
"time"
"modernc.org/sqlite"
@ -96,17 +95,9 @@ func (c *sqliteConn) QueryContext(ctx context.Context, query string, args []driv
}
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
const onClose = "PRAGMA analysis_limit=1000; PRAGMA optimize;"
_, _ = c.connIface.ExecContext(ctx, onClose, nil)
// Done.
cncl()
_, _ = c.connIface.ExecContext(context.Background(), onClose, nil)
// Finally, close the conn.
err = c.connIface.Close()

View File

@ -22,7 +22,6 @@ package sqlite
import (
"context"
"database/sql/driver"
"time"
"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) {
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)
// see: https://www.sqlite.org/pragma.html#pragma_optimize
const onClose = "PRAGMA analysis_limit=1000; PRAGMA optimize;"
_ = raw.Exec(onClose)
// Unset timeout context.
_ = raw.SetInterrupt(old)
cncl()
// Finally, close.
err = raw.Close()
return