| @@ -11,8 +11,6 @@ import ( |
| 11 | "github.com/mattn/go-sqlite3" | 11 | "github.com/mattn/go-sqlite3" |
| 12 | ) | 12 | ) |
| 13 | | 13 | |
| 14 | -const DSN = "_journal_mode=WAL&_busy_timeout=30000&_synchronous=NORMAL&_cache=shared" | | |
| 15 | - | | |
| 16 | type DB struct { | 14 | type DB struct { |
| 17 | *sql.DB | 15 | *sql.DB |
| 18 | } | 16 | } |
| @@ -42,7 +40,11 @@ func OpenAll(basePath string) (*Databases, error) { |
| 42 | return err | 40 | return err |
| 43 | } | 41 | } |
| 44 | for _, p := range []string{ | 42 | for _, p := range []string{ |
| | 43 | + `PRAGMA journal_mode=WAL`, |
| 45 | `PRAGMA wal_autocheckpoint = 1000`, | 44 | `PRAGMA wal_autocheckpoint = 1000`, |
| | 45 | + `PRAGMA busy_timeout = 30000`, |
| | 46 | + `PRAGMA synchronous = NORMAL`, |
| | 47 | + `PRAGMA cache = shared`, |
| 46 | `PRAGMA temp_store = MEMORY`, | 48 | `PRAGMA temp_store = MEMORY`, |
| 47 | `PRAGMA mmap_size = 268435456`, | 49 | `PRAGMA mmap_size = 268435456`, |
| 48 | } { | 50 | } { |
| @@ -53,14 +55,40 @@ func OpenAll(basePath string) (*Databases, error) { |
| 53 | if _, err := conn.Exec(fmt.Sprintf("ATTACH DATABASE '%s' AS articles", articlesPath), nil); err != nil { | 55 | if _, err := conn.Exec(fmt.Sprintf("ATTACH DATABASE '%s' AS articles", articlesPath), nil); err != nil { |
| 54 | return err | 56 | return err |
| 55 | } | 57 | } |
| | 58 | + for _, p := range []string{ |
| | 59 | + `PRAGMA articles.journal_mode=WAL`, |
| | 60 | + `PRAGMA articles.wal_autocheckpoint = 1000`, |
| | 61 | + `PRAGMA articles.busy_timeout = 30000`, |
| | 62 | + `PRAGMA articles.synchronous = NORMAL`, |
| | 63 | + `PRAGMA articles.cache = shared`, |
| | 64 | + `PRAGMA articles.temp_store = MEMORY`, |
| | 65 | + `PRAGMA articles.mmap_size = 268435456`, |
| | 66 | + } { |
| | 67 | + if _, err := conn.Exec(p, nil); err != nil { |
| | 68 | + return err |
| | 69 | + } |
| | 70 | + } |
| 56 | if _, err := conn.Exec(fmt.Sprintf("ATTACH DATABASE '%s' AS recs", recsPath), nil); err != nil { | 71 | if _, err := conn.Exec(fmt.Sprintf("ATTACH DATABASE '%s' AS recs", recsPath), nil); err != nil { |
| 57 | return err | 72 | return err |
| 58 | } | 73 | } |
| | 74 | + for _, p := range []string{ |
| | 75 | + `PRAGMA recs.journal_mode=WAL`, |
| | 76 | + `PRAGMA recs.wal_autocheckpoint = 1000`, |
| | 77 | + `PRAGMA recs.busy_timeout = 30000`, |
| | 78 | + `PRAGMA recs.synchronous = NORMAL`, |
| | 79 | + `PRAGMA recs.cache = shared`, |
| | 80 | + `PRAGMA recs.temp_store = MEMORY`, |
| | 81 | + `PRAGMA recs.mmap_size = 268435456`, |
| | 82 | + } { |
| | 83 | + if _, err := conn.Exec(p, nil); err != nil { |
| | 84 | + return err |
| | 85 | + } |
| | 86 | + } |
| 59 | return nil | 87 | return nil |
| 60 | }, | 88 | }, |
| 61 | }) | 89 | }) |
| 62 | | 90 | |
| 63 | - db, err := sql.Open(driverName, basePath+"_users?cache=shared&"+DSN) | 91 | + db, err := sql.Open(driverName, basePath+"_users") |
| 64 | if err != nil { | 92 | if err != nil { |
| 65 | return nil, err | 93 | return nil, err |
| 66 | } | 94 | } |