mirror of
https://github.com/axllent/mailpit.git
synced 2026-04-18 12:09:30 +00:00
Chore: Improve transaction handling in pruneMessages and fix loop continuation in InitDB
This commit is contained in:
@@ -128,6 +128,9 @@ func pruneMessages() {
|
||||
return
|
||||
}
|
||||
|
||||
// roll back if it fails
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
|
||||
args := make([]any, len(ids))
|
||||
for i, id := range ids {
|
||||
args[i] = id
|
||||
@@ -151,13 +154,8 @@ func pruneMessages() {
|
||||
return
|
||||
}
|
||||
|
||||
err = tx.Commit()
|
||||
|
||||
if err != nil {
|
||||
if err = tx.Commit(); err != nil {
|
||||
logger.Log().Errorf("[db] %s", err.Error())
|
||||
if err := tx.Rollback(); err != nil {
|
||||
logger.Log().Errorf("[db] %s", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
if err := pruneUnusedTags(); err != nil {
|
||||
|
||||
@@ -110,7 +110,7 @@ func InitDB() error {
|
||||
logger.Log().Infof("[db] reconnecting in 5 seconds (attempt %d/5)", i)
|
||||
time.Sleep(5 * time.Second)
|
||||
} else {
|
||||
continue
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user