SkipDefaultTransaction (gorm.Config) is set (or default) to "false"; consider skipping the default transaction by setting the value of field "true", if not required
20 panic(err)
21 }
22 dsn := "host=" + os.Getenv("POSTGRES_HOST") + " user=nwf password=root dbname=ps1 port=5432 sslmode=disable"
23 DB, err := gorm.Open(postgres.Open(dsn), &gorm.Config{}) 24
25 if err != nil {
26 log.Fatal(err)
Description
GORM performs write (create/update/delete) operations inside a transaction to ensure data
consistency. Consider disabling it during initialization if it is not required, and it'd
gain about 30%+ performance improvement after setting SkipDefaultTransaction
to true
.
Please note that toggling the SkipDefaultTransaction
from false
to true
might lead
to performance gains but can introduce bugs because, in some cases, ensuring data consistency
might be preferred.
Bad practice
_ = &gorm.Config{SkipDefaultTransaction: false}
Recommended
_ = &gorm.Config{SkipDefaultTransaction: true}