mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2025-04-19 21:42:24 +00:00
Enhance database initialization in db.go (#2645)
- Updated GORM configuration to skip default transactions and prepare statements. - Modified the database connection string to include caching and journal mode settings. - Executed several PRAGMA statements to optimize SQLite performance and enable foreign key support. These changes improve database handling and performance in the application. Co-authored-by: Zakhar Izmaylov <ptdev@kedruss.ru>
This commit is contained in:
parent
7b7eb98acb
commit
66fe84181b
1 changed files with 24 additions and 2 deletions
|
@ -83,8 +83,30 @@ func InitDB(dbPath string) error {
|
||||||
|
|
||||||
c := &gorm.Config{
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue