Fix database connection pool contention (maybe)
Instead of acquiring a connection per service per request, we acquire connections more often but at a more granular level, meaning they're also disposed of more quickly instead of staying for a long time in case of long-running commands or leaks.
This commit is contained in:
@@ -33,22 +33,17 @@ namespace PluralKit.API
|
||||
services.AddMvc(opts => { })
|
||||
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
|
||||
.AddJsonOptions(opts => { opts.SerializerSettings.BuildSerializerSettings(); });
|
||||
|
||||
|
||||
services
|
||||
.AddTransient<SystemStore>()
|
||||
.AddTransient<MemberStore>()
|
||||
.AddTransient<SwitchStore>()
|
||||
.AddTransient<MessageStore>()
|
||||
|
||||
|
||||
.AddScoped<TokenAuthService>()
|
||||
|
||||
|
||||
.AddTransient(_ => Configuration.GetSection("PluralKit").Get<CoreConfig>() ?? new CoreConfig())
|
||||
.AddScoped<IDbConnection>(svc =>
|
||||
{
|
||||
var conn = new NpgsqlConnection(svc.GetRequiredService<CoreConfig>().Database);
|
||||
conn.Open();
|
||||
return conn;
|
||||
});
|
||||
.AddSingleton(svc => new DbConnectionFactory(svc.GetRequiredService<CoreConfig>().Database));
|
||||
}
|
||||
|
||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
|
||||
Reference in New Issue
Block a user