mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2025-03-01 01:20:49 +03: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
@ -83,8 +83,30 @@ func InitDB(dbPath string) error {
|
||||
|
||||
c := &gorm.Config{
|
||||
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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user