|
40 | 40 | LogSQL bool
|
41 | 41 | Charset string
|
42 | 42 | Timeout int // seconds
|
43 |
| - SQliteJournalMode string |
44 | 43 | UseSQLite3 bool
|
45 | 44 | UseMySQL bool
|
46 | 45 | UseMSSQL bool
|
@@ -90,24 +89,10 @@ func InitDBConfig() {
|
90 | 89 | if Database.UseMySQL && defaultCharset != "utf8mb4" {
|
91 | 90 | log.Error("Deprecated database mysql charset utf8 support, please use utf8mb4 or convert utf8 to utf8mb4.")
|
92 | 91 | }
|
93 |
| - |
94 | 92 | if Database.UseSQLite3 {
|
95 | 93 | Database.Path = sec.Key("PATH").MustString(filepath.Join(AppDataPath, "gitea.db"))
|
96 | 94 | 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 | 95 | }
|
110 |
| - |
111 | 96 | Database.MaxIdleConns = sec.Key("MAX_IDLE_CONNS").MustInt(2)
|
112 | 97 | if Database.UseMySQL {
|
113 | 98 | Database.ConnMaxLifetime = sec.Key("CONN_MAX_LIFETIME").MustDuration(3 * time.Second)
|
@@ -153,8 +138,17 @@ func DBConnStr() (string, error) {
|
153 | 138 | if err := os.MkdirAll(path.Dir(Database.Path), os.ModePerm); err != nil {
|
154 | 139 | return "", fmt.Errorf("Failed to create directories: %v", err)
|
155 | 140 | }
|
| 141 | + |
| 142 | + // WAL mode is preferred for better concurent write performance, but needs special VFS driver features, |
| 143 | + // which are guaranteed to be available for unix & windows OSes: https://www.sqlite.org/wal.html |
| 144 | + journalMode := "DELETE" |
| 145 | + switch runtime.GOOS { |
| 146 | + // probably the BSDs are supported too, but i found no information on this - better safe than sorry. |
| 147 | + case "windows", "linux": // "darwin", "freebsd", "openbsd", "netbsd": |
| 148 | + journalMode = "WAL" |
| 149 | + } |
156 | 150 | connStr = fmt.Sprintf("file:%s?cache=shared&mode=rwc&_busy_timeout=%d&_txlock=immediate&_journal_mode=%s",
|
157 |
| - Database.Path, Database.Timeout, Database.SQliteJournalMode) |
| 151 | + Database.Path, Database.Timeout, journalMode) |
158 | 152 | default:
|
159 | 153 | return "", fmt.Errorf("Unknown database type: %s", Database.Type)
|
160 | 154 | }
|
|
0 commit comments