Skip to content

Commit a6b8443

Browse files
committed
make default value OS dependent
1 parent f606e12 commit a6b8443

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

docs/content/doc/advanced/config-cheat-sheet.en-us.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ The following configuration set `Content-Type: application/vnd.android.package-a
382382
- `verify-ca`: Enable TLS with verification of the database server certificate against its root certificate.
383383
- `verify-full`: Enable TLS and verify the database server name matches the given certificate in either the `Common Name` or `Subject Alternative Name` fields.
384384
- `SQLITE_TIMEOUT`: **500**: Query timeout for SQLite3 only.
385-
- `SQLITE_JOURNAL_MODE`: **DELETE**: Change journal mode for SQlite3. Can be used to enable [WAL mode](https://www.sqlite.org/wal.html) when high load causes write congestion. See [SQlite3 docs](https://www.sqlite.org/pragma.html#pragma_journal_mode) for possible values.
385+
- `SQLITE_JOURNAL_MODE`: on windows & linux: **WAL**, otherwise **DELETE**: Change journal mode for SQlite3. See [SQlite3 docs](https://www.sqlite.org/pragma.html#pragma_journal_mode) for possible values.
386386
- `ITERATE_BUFFER_SIZE`: **50**: Internal buffer size for iterating.
387387
- `CHARSET`: **utf8mb4**: For MySQL only, either "utf8" or "utf8mb4". NOTICE: for "utf8mb4" you must use MySQL InnoDB > 5.6. Gitea is unable to check this.
388388
- `PATH`: **data/gitea.db**: For SQLite3 only, the database file path.

modules/setting/database.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"os"
1212
"path"
1313
"path/filepath"
14+
"runtime"
1415
"strings"
1516
"time"
1617

@@ -90,9 +91,22 @@ func InitDBConfig() {
9091
log.Error("Deprecated database mysql charset utf8 support, please use utf8mb4 or convert utf8 to utf8mb4.")
9192
}
9293

93-
Database.Path = sec.Key("PATH").MustString(filepath.Join(AppDataPath, "gitea.db"))
94-
Database.Timeout = sec.Key("SQLITE_TIMEOUT").MustInt(500)
95-
Database.SQliteJournalMode = sec.Key("SQLITE_JOURNAL_MODE").MustString("DELETE")
94+
if Database.UseSQLite3 {
95+
Database.Path = sec.Key("PATH").MustString(filepath.Join(AppDataPath, "gitea.db"))
96+
Database.Timeout = sec.Key("SQLITE_TIMEOUT").MustInt(500)
97+
98+
// WAL mode is preferred for better concurent write performance, but needs special VFS driver features,
99+
// which are guaranteed to be available for unix & windows OSes
100+
var defaultJournalMode string
101+
switch runtime.GOOS {
102+
// probably the BSDs are supported too, but i found no information on this - better safe than sorry.
103+
case "windows", "linux": // "darwin", "freebsd", "openbsd", "netbsd":
104+
defaultJournalMode = "WAL"
105+
default:
106+
defaultJournalMode = "DELETE"
107+
}
108+
Database.SQliteJournalMode = sec.Key("SQLITE_JOURNAL_MODE").MustString(defaultJournalMode)
109+
}
96110

97111
Database.MaxIdleConns = sec.Key("MAX_IDLE_CONNS").MustInt(2)
98112
if Database.UseMySQL {

0 commit comments

Comments
 (0)