fix(channelserver): configure DB pool and add transactions for guild ops

sqlx.Open was called with no pool configuration, risking PostgreSQL
connection exhaustion under load. Set max open/idle conns and lifetimes.

CreatePost INSERT + soft-delete UPDATE were two separate queries with
no transaction, risking inconsistent state on partial failure.

CollectAdventure used SELECT then UPDATE without a lock, allowing
concurrent guild members to double-collect. Now uses SELECT FOR UPDATE
within a transaction.
This commit is contained in:
Houmgaor
2026-02-21 00:29:09 +01:00
parent 0a489e7cc5
commit f9d9260274
2 changed files with 32 additions and 7 deletions

View File

@@ -136,6 +136,13 @@ func main() {
if err != nil {
preventClose(config, fmt.Sprintf("Database: Failed to ping, %s", err.Error()))
}
// Configure connection pool to avoid exhausting PostgreSQL under load.
db.SetMaxOpenConns(50)
db.SetMaxIdleConns(10)
db.SetConnMaxLifetime(5 * time.Minute)
db.SetConnMaxIdleTime(2 * time.Minute)
logger.Info("Database: Started successfully")
// Pre-compute all server IDs this instance will own, so we only