nandi/gleanpublic Fork 0
8943a72
Commits
Clone
git clone https://git.rickub.com/nandi/glean.git
git clone ssh://git@rickub.com/nandi/glean.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

Enable WAL for all dbsUnverified

Julien Robert committed 2026-04-24T02:17:14+02:00 Browse files
8943a72 parent: bd2dd69
modified internal/db/db.go +31 -3
@@ -11,8 +11,6 @@ import (
1111 "github.com/mattn/go-sqlite3"
1212 )
1313
14-const DSN = "_journal_mode=WAL&_busy_timeout=30000&_synchronous=NORMAL&_cache=shared"
15-
1614 type DB struct {
1715 *sql.DB
1816 }
@@ -42,7 +40,11 @@ func OpenAll(basePath string) (*Databases, error) {
4240 return err
4341 }
4442 for _, p := range []string{
43+ `PRAGMA journal_mode=WAL`,
4544 `PRAGMA wal_autocheckpoint = 1000`,
45+ `PRAGMA busy_timeout = 30000`,
46+ `PRAGMA synchronous = NORMAL`,
47+ `PRAGMA cache = shared`,
4648 `PRAGMA temp_store = MEMORY`,
4749 `PRAGMA mmap_size = 268435456`,
4850 } {
@@ -53,14 +55,40 @@ func OpenAll(basePath string) (*Databases, error) {
5355 if _, err := conn.Exec(fmt.Sprintf("ATTACH DATABASE '%s' AS articles", articlesPath), nil); err != nil {
5456 return err
5557 }
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+ }
5671 if _, err := conn.Exec(fmt.Sprintf("ATTACH DATABASE '%s' AS recs", recsPath), nil); err != nil {
5772 return err
5873 }
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+ }
5987 return nil
6088 },
6189 })
6290
63- db, err := sql.Open(driverName, basePath+"_users?cache=shared&"+DSN)
91+ db, err := sql.Open(driverName, basePath+"_users")
6492 if err != nil {
6593 return nil, err
6694 }
@@ -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.DB15 *sql.DB
18 }16 }
@@ -42,7 +40,11 @@ func OpenAll(basePath string) (*Databases, error) {
42 return err40 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 err56 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 err72 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 nil87 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, err93 return nil, err
66 }94 }