Skip to content

opt: add database connection limit, close #1459#1462

Merged
looplj merged 1 commit into
unstablefrom
dev-tmp
Apr 23, 2026
Merged

opt: add database connection limit, close #1459#1462
looplj merged 1 commit into
unstablefrom
dev-tmp

Conversation

@looplj

@looplj looplj commented Apr 23, 2026

Copy link
Copy Markdown
Owner

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looplj has reached the 50-review limit for trial accounts. To continue receiving code reviews, upgrade your plan.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces configurable database connection pool settings, including maximum open and idle connections, as well as connection lifetime and idle time limits. It also updates the pgx dependency and disables window focus refetching for the useRequests hook in the frontend. Feedback includes a suggestion to remove the > 0 checks when applying database configurations to allow for zero-value settings (e.g., disabling pooling) and a recommendation to apply the refetchOnWindowFocus optimization consistently across other hooks in the frontend.

Comment thread internal/server/db/ent.go
Comment on lines +62 to +76
if cfg.MaxOpenConns > 0 {
sqlDB.SetMaxOpenConns(cfg.MaxOpenConns)
}

if cfg.MaxIdleConns > 0 {
sqlDB.SetMaxIdleConns(cfg.MaxIdleConns)
}

if cfg.ConnMaxLifetime > 0 {
sqlDB.SetConnMaxLifetime(cfg.ConnMaxLifetime)
}

if cfg.ConnMaxIdleTime > 0 {
sqlDB.SetConnMaxIdleTime(cfg.ConnMaxIdleTime)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The checks for > 0 prevent setting these parameters to their 'zero' values (e.g., unlimited or disabled). Specifically for MaxIdleConns, the default in Go's sql.DB is 2. If a user explicitly wants to disable connection pooling by setting max_idle_conns: 0 in the configuration, this check will skip the call, leaving the pool with the default 2 idle connections. Since default values are provided in the configuration loader, these fields will always be populated. It is cleaner and more correct to apply the values directly.

Suggested change
if cfg.MaxOpenConns > 0 {
sqlDB.SetMaxOpenConns(cfg.MaxOpenConns)
}
if cfg.MaxIdleConns > 0 {
sqlDB.SetMaxIdleConns(cfg.MaxIdleConns)
}
if cfg.ConnMaxLifetime > 0 {
sqlDB.SetConnMaxLifetime(cfg.ConnMaxLifetime)
}
if cfg.ConnMaxIdleTime > 0 {
sqlDB.SetConnMaxIdleTime(cfg.ConnMaxIdleTime)
}
sqlDB.SetMaxOpenConns(cfg.MaxOpenConns)
sqlDB.SetMaxIdleConns(cfg.MaxIdleConns)
sqlDB.SetConnMaxLifetime(cfg.ConnMaxLifetime)
sqlDB.SetConnMaxIdleTime(cfg.ConnMaxIdleTime)

}
},
enabled,
refetchOnWindowFocus: false,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The refetchOnWindowFocus: false optimization is applied to the useRequests hook but not to other similar hooks in this file, such as useRequestExecutions. Consider applying this setting consistently across the feature to ensure uniform behavior and optimize performance.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 3 additional findings.

Open in Devin Review

@looplj looplj merged commit e62c82a into unstable Apr 23, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant