switch database to wal mode

This commit is contained in:
Ted Unangst 2022-05-31 03:06:09 -04:00
parent 3c650e3979
commit 65ba713c17
5 changed files with 22 additions and 4 deletions

4
README
View File

@ -20,7 +20,7 @@ This does not imply the goal is to be what you want.
-- build -- build
It should be sufficient to type make after unpacking a release. It should be sufficient to type make after unpacking a release.
You'll need a go compiler version 1.13 or later. And libsqlite3. You'll need a go compiler version 1.16 or later. And libsqlite3.
Even on a fast machine, building from source can take several seconds. Even on a fast machine, building from source can take several seconds.
@ -42,7 +42,7 @@ Then run honk.
-- upgrade -- upgrade
cp honk.db backup.db old-honk backup `date +backup-%F`
./honk upgrade ./honk upgrade
./honk ./honk

View File

@ -19,8 +19,8 @@ import (
"bytes" "bytes"
"crypto/sha512" "crypto/sha512"
"database/sql" "database/sql"
"encoding/json"
_ "embed" _ "embed"
"encoding/json"
"fmt" "fmt"
"html/template" "html/template"
"sort" "sort"

View File

@ -2,6 +2,8 @@ changelog
=== next === next
+ Switch database to WAL mode.
- go version 1.16 required. - go version 1.16 required.
+ Specify banner: image in profile. + Specify banner: image in profile.

View File

@ -22,7 +22,7 @@ import (
"time" "time"
) )
var myVersion = 40 var myVersion = 41
type dbexecer interface { type dbexecer interface {
Exec(query string, args ...interface{}) (sql.Result, error) Exec(query string, args ...interface{}) (sql.Result, error)
@ -200,6 +200,12 @@ func upgradedb() {
doordie(db, "update config set value = 40 where key = 'dbversion'") doordie(db, "update config set value = 40 where key = 'dbversion'")
fallthrough fallthrough
case 40: case 40:
doordie(db, "PRAGMA journal_mode=WAL")
blobdb := openblobdb()
doordie(blobdb, "PRAGMA journal_mode=WAL")
doordie(db, "update config set value = 41 where key = 'dbversion'")
fallthrough
case 41:
default: default:
elog.Fatalf("can't upgrade unknown version %d", dbversion) elog.Fatalf("can't upgrade unknown version %d", dbversion)

10
util.go
View File

@ -100,6 +100,11 @@ func initdb() {
os.Exit(1) os.Exit(1)
}() }()
_, err = db.Exec("PRAGMA journal_mode=WAL")
if err != nil {
elog.Print(err)
return
}
for _, line := range strings.Split(sqlSchema, ";") { for _, line := range strings.Split(sqlSchema, ";") {
_, err = db.Exec(line) _, err = db.Exec(line)
if err != nil { if err != nil {
@ -176,6 +181,11 @@ func initblobdb() {
elog.Print(err) elog.Print(err)
return return
} }
_, err = blobdb.Exec("PRAGMA journal_mode=WAL")
if err != nil {
elog.Print(err)
return
}
_, err = blobdb.Exec("create table filedata (xid text, media text, hash text, content blob)") _, err = blobdb.Exec("create table filedata (xid text, media text, hash text, content blob)")
if err != nil { if err != nil {
elog.Print(err) elog.Print(err)