Skip to content

Commit 8d51213

Browse files
committed
Do not double-cache the filename
1 parent 039c084 commit 8d51213

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

lib/sqlrunner.go

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
_ "modernc.org/sqlite"
2121
)
2222

23-
var sf singleflight.Group
23+
var sf = &singleflight.Group{}
2424

2525
func init() {
2626
// MySQL-compatible functions
@@ -118,9 +118,6 @@ type SQLRunner struct {
118118
schema string
119119

120120
cache *lru.Cache[string, *QueryResult]
121-
122-
// cache
123-
filename string
124121
}
125122

126123
func NewSQLRunner(schema string) (*SQLRunner, error) {
@@ -212,16 +209,12 @@ func (r *SQLRunner) Query(ctx context.Context, query string) (*QueryResult, erro
212209
//
213210
// You should close the database after using it.
214211
func (r *SQLRunner) getSqliteInstance() (*sql.DB, error) {
215-
if r.filename != "" {
216-
filename, err := initializeThreadSafe(r.schema)
217-
if err != nil {
218-
return nil, NewSchemaError(err)
219-
}
220-
221-
r.filename = filename
212+
filename, err := initializeThreadSafe(r.schema)
213+
if err != nil {
214+
return nil, NewSchemaError(err)
222215
}
223216

224-
db, err := sql.Open("sqlite", fmt.Sprintf("file:%s?mode=ro", r.filename))
217+
db, err := sql.Open("sqlite", fmt.Sprintf("file:%s?mode=ro", filename))
225218
if err != nil {
226219
return nil, fmt.Errorf("open schema database (r/o): %w", err)
227220
}

0 commit comments

Comments
 (0)