minor cleanup changes

This commit is contained in:
crn4
2025-10-30 18:03:06 +01:00
parent 4896428d76
commit ab8a2baa32
2 changed files with 10 additions and 6 deletions

View File

@@ -49,6 +49,11 @@ const (
accountAndIDsQueryCondition = "account_id = ? AND id IN ?"
accountIDCondition = "account_id = ?"
peerNotFoundFMT = "peer %s not found"
pgMaxConnections = 30
pgMinConnections = 5
pgMaxConnLifetime = 60 * time.Minute
pgHealthCheckPeriod = 1 * time.Minute
)
// SqlStore represents an account storage backed by a Sql DB persisted to disk
@@ -2101,10 +2106,10 @@ func connectToPgDb(ctx context.Context, dsn string) (*pgxpool.Pool, error) {
return nil, fmt.Errorf("unable to parse database config: %w", err)
}
config.MaxConns = 10
config.MinConns = 2
config.MaxConnLifetime = time.Hour
config.HealthCheckPeriod = time.Minute
config.MaxConns = pgMaxConnections
config.MinConns = pgMinConnections
config.MaxConnLifetime = pgMaxConnLifetime
config.HealthCheckPeriod = pgHealthCheckPeriod
pool, err := pgxpool.NewWithConfig(ctx, config)
if err != nil {
@@ -2116,7 +2121,6 @@ func connectToPgDb(ctx context.Context, dsn string) (*pgxpool.Pool, error) {
return nil, fmt.Errorf("unable to ping database: %w", err)
}
fmt.Println("Successfully connected to the database!")
return pool, nil
}

View File

@@ -42,7 +42,7 @@ func (s *SqlStore) GetAccountSlow(ctx context.Context, accountID string) (*types
var account types.Account
result := s.db.Model(&account).
Omit("GroupsG").
Preload("UsersG.PATsG"). // have to be specifies as this is nester reference
Preload("UsersG.PATsG"). // have to be specified as this is nested reference
Preload(clause.Associations).
Take(&account, idQueryCondition, accountID)
if result.Error != nil {