Limit postgres database concurrency (#17246)

This commit is contained in:
Pieter-Jan Briers
2023-06-10 13:52:08 +02:00
committed by GitHub
parent f055faeebd
commit 50257c3bd7
5 changed files with 30 additions and 14 deletions

View File

@@ -20,22 +20,21 @@ namespace Content.Server.Database
{
private readonly Func<DbContextOptions<SqliteServerDbContext>> _options;
// This doesn't allow concurrent access so that's what the semaphore is for.
// That said, this is bloody SQLite, I don't even think EFCore bothers to truly async it.
private readonly SemaphoreSlim _prefsSemaphore;
private readonly Task _dbReadyTask;
private int _msDelay;
public ServerDbSqlite(Func<DbContextOptions<SqliteServerDbContext>> options, bool inMemory)
public ServerDbSqlite(
Func<DbContextOptions<SqliteServerDbContext>> options,
bool inMemory,
IConfigurationManager cfg)
{
_options = options;
var prefsCtx = new SqliteServerDbContext(options());
var cfg = IoCManager.Resolve<IConfigurationManager>();
// When inMemory we re-use the same connection, so we can't have any concurrency.
var concurrency = inMemory ? 1 : cfg.GetCVar(CCVars.DatabaseSqliteConcurrency);
_prefsSemaphore = new SemaphoreSlim(concurrency, concurrency);