Add support for different journal modes
Signed-off-by: Jonas Franz <info@jonasfranz.software>
This commit is contained in:
parent
85414d8b75
commit
f06e9c66b2
|
|
@ -213,6 +213,8 @@ SSL_MODE = disable
|
|||
PATH = data/gitea.db
|
||||
; For "sqlite3" only. Query timeout
|
||||
SQLITE_TIMEOUT = 500
|
||||
; For "sqlite3" only. Journal mode
|
||||
JOURNAL_MODE = WLA
|
||||
; For iterate buffer, default is 50
|
||||
ITERATE_BUFFER_SIZE = 50
|
||||
; Show the database generated SQL
|
||||
|
|
|
|||
|
|
@ -129,6 +129,9 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`.
|
|||
- `PASSWD`: **\<empty\>**: Database user password. Use \`your password\` for quoting if you use special characters in the password.
|
||||
- `SSL_MODE`: **disable**: For PostgreSQL only.
|
||||
- `PATH`: **data/gitea.db**: For SQLite3 only, the database file path.
|
||||
- `JOURNAL_MODE` **WLA**: For SQLite3 only, the journal mode. Use `DELETE` mode if you're running Gitea on a network file system
|
||||
or your operating system does not support VFS. Please checkout the [WAL documentation](https://www.sqlite.org/wal.html) to learn more. WLA
|
||||
mode will result in a better performance and reduces `database locked` errors.
|
||||
- `LOG_SQL`: **true**: Log the executed SQL.
|
||||
|
||||
## Indexer (`indexer`)
|
||||
|
|
|
|||
|
|
@ -58,8 +58,8 @@ var (
|
|||
|
||||
// DbCfg holds the database settings
|
||||
DbCfg struct {
|
||||
Type, Host, Name, User, Passwd, Path, SSLMode string
|
||||
Timeout int
|
||||
Type, Host, Name, User, Passwd, Path, SSLMode, JournalMode string
|
||||
Timeout int
|
||||
}
|
||||
|
||||
// EnableSQLite3 use SQLite3
|
||||
|
|
@ -154,6 +154,7 @@ func LoadConfigs() {
|
|||
DbCfg.SSLMode = sec.Key("SSL_MODE").String()
|
||||
DbCfg.Path = sec.Key("PATH").MustString("data/gitea.db")
|
||||
DbCfg.Timeout = sec.Key("SQLITE_TIMEOUT").MustInt(500)
|
||||
DbCfg.JournalMode = sec.Key("JOURNAL_MODE").MustString("WLA")
|
||||
|
||||
sec = setting.Cfg.Section("indexer")
|
||||
setting.Indexer.IssuePath = sec.Key("ISSUE_INDEXER_PATH").MustString(path.Join(setting.AppDataPath, "indexers/issues.bleve"))
|
||||
|
|
@ -244,8 +245,21 @@ func getEngine() (*xorm.Engine, error) {
|
|||
default:
|
||||
return nil, fmt.Errorf("Unknown database type: %s", DbCfg.Type)
|
||||
}
|
||||
|
||||
return xorm.NewEngine(DbCfg.Type, connStr)
|
||||
e, err := xorm.NewEngine(DbCfg.Type, connStr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if DbCfg.Type == "sqlite" {
|
||||
journalMode := "WLA" // Using WLA as default mode
|
||||
if len(DbCfg.JournalMode) == 0 {
|
||||
journalMode = DbCfg.JournalMode
|
||||
}
|
||||
_, err := e.Exec("PRAGMA journal_mode = ?;", journalMode)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return e, nil
|
||||
}
|
||||
|
||||
// NewTestEngine sets a new test xorm.Engine
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user