Chore: Improve transaction handling in pruneMessages and fix loop continuation in InitDB

This commit is contained in:
Ralph Slooten
2026-03-10 11:53:36 +13:00
parent 140633718c
commit fc0b016549
2 changed files with 5 additions and 7 deletions

View File

@@ -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 {

View File

@@ -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
}
}