set SetMaxOpenConns, close rows when QueryEvents finishes

This commit is contained in:
0x0ff
2022-12-30 17:18:23 +01:00
committed by fiatjaf
parent 8b3ff7ac26
commit 9ba958e9a0
2 changed files with 5 additions and 0 deletions

View File

@@ -12,6 +12,9 @@ func (b *PostgresBackend) Init() error {
return err
}
// sqlx default is 0 (unlimited), while postgresql by default accepts up to 100 connections
db.SetMaxOpenConns(80)
db.Mapper = reflectx.NewMapperFunc("json", sqlx.NameMapper)
b.DB = db

View File

@@ -139,6 +139,8 @@ func (b PostgresBackend) QueryEvents(filter *nostr.Filter) (events []nostr.Event
return nil, fmt.Errorf("failed to fetch events using query %q: %w", query, err)
}
defer rows.Close()
for rows.Next() {
var evt nostr.Event
var timestamp int64