Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Enhance database initialization in db.go #2645

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions database/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,31 @@ func InitDB(dbPath string) error {
}

c := &gorm.Config{
Logger: gormLogger,
Logger: gormLogger,
SkipDefaultTransaction: true,
PrepareStmt: true,
}
db, err = gorm.Open(sqlite.Open(dbPath), c)

dsn := dbPath + "?cache=shared&_journal_mode=WAL&_synchronous=NORMAL"
db, err = gorm.Open(sqlite.Open(dsn), c)
if err != nil {
return err
}

sqlDB, err := db.DB()
if err != nil {
return err
}

_, err = sqlDB.Exec("PRAGMA cache_size = -64000;")
if err != nil {
return err
}
_, err = sqlDB.Exec("PRAGMA temp_store = MEMORY;")
if err != nil {
return err
}
_, err = sqlDB.Exec("PRAGMA foreign_keys = ON;")
if err != nil {
return err
}
Expand Down