Backend: Fix pooling configuration always overriding connection string parameters

This commit is contained in:
solidDoWant 2025-05-02 23:04:13 +00:00 committed by Zoe Roux
parent 454855b299
commit 7d04da2eae

View File

@ -33,15 +33,19 @@ public static class PostgresModule
{ {
public static NpgsqlDataSource CreateDataSource(IConfiguration configuration) public static NpgsqlDataSource CreateDataSource(IConfiguration configuration)
{ {
var connectionString = configuration.GetValue<string>("POSTGRES_URL");
// Load the connection string from the environment variable, as well as standard libpq environment variables // Load the connection string from the environment variable, as well as standard libpq environment variables
// (PGUSER, PGPASSWORD, PGHOST, PGPORT, PGDATABASE, etc.) // (PGUSER, PGPASSWORD, PGHOST, PGPORT, PGDATABASE, etc.)
NpgsqlConnectionStringBuilder conBuilder = NpgsqlConnectionStringBuilder conBuilder = new(connectionString ?? "");
new(configuration.GetValue<string>("POSTGRES_URL") ?? "") // Set defaults when no explicit connection string is provided. This cannot be set if the connection string
{ // is provided, or it will override connection string values.
Pooling = true, if (string.IsNullOrEmpty(connectionString))
MaxPoolSize = 95, {
Timeout = 30 conBuilder.Pooling = true;
}; conBuilder.MaxPoolSize = 95;
conBuilder.Timeout = 30;
}
string? oldVarUsername = configuration.GetValue<string>("POSTGRES_USER"); string? oldVarUsername = configuration.GetValue<string>("POSTGRES_USER");
if (!string.IsNullOrEmpty(oldVarUsername)) if (!string.IsNullOrEmpty(oldVarUsername))