perf: optimize sqlite3 (#3074)

- use journal mode to WAL
- set locking mode to EXCLUSIVE
- set auto vacuum

ref:
 - https://www.sqlite.org/pragma.html#pragma_journal_mode
 - https://www.sqlite.org/pragma.html#pragma_locking_mode
 - https://www.sqlite.org/pragma.html#pragma_auto_vacuum
pull/3078/head
Aoang 2023-01-17 17:06:11 +08:00 committed by GitHub
parent 8df1455f25
commit 9c7e451c03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 1 deletions

View File

@ -51,7 +51,8 @@ func InitDB() {
if !(strings.HasSuffix(database.DBFile, ".db") && len(database.DBFile) > 3) {
log.Fatalf("db name error.")
}
dB, err = gorm.Open(sqlite.Open(database.DBFile), gormConfig)
dB, err = gorm.Open(sqlite.Open(fmt.Sprintf("%s?_journal=WAL&_locking=EXCLUSIVE&_vacuum=incremental",
database.DBFile)), gormConfig)
}
case "mysql":
{