diff --git a/server/RdtClient.Data/DiConfig.cs b/server/RdtClient.Data/DiConfig.cs index 1a1b29e..636004d 100644 --- a/server/RdtClient.Data/DiConfig.cs +++ b/server/RdtClient.Data/DiConfig.cs @@ -14,7 +14,7 @@ public static class DiConfig throw new("Invalid database path found in appSettings"); } - var connectionString = $"Data Source={appSettings.Database.Path}"; + var connectionString = $"Data Source={appSettings.Database.Path};Cache=Shared;Pooling=True;Command Timeout=30"; services.AddDbContext(options => options.UseSqlite(connectionString)); services.AddScoped(); diff --git a/server/RdtClient.Service/BackgroundServices/Startup.cs b/server/RdtClient.Service/BackgroundServices/Startup.cs index d5c359a..551f30d 100644 --- a/server/RdtClient.Service/BackgroundServices/Startup.cs +++ b/server/RdtClient.Service/BackgroundServices/Startup.cs @@ -25,6 +25,12 @@ public class Startup(IServiceProvider serviceProvider) : IHostedService var dbContext = scope.ServiceProvider.GetRequiredService(); await dbContext.Database.MigrateAsync(cancellationToken); + // Configure SQLite for better concurrency and performance + await dbContext.Database.ExecuteSqlRawAsync("PRAGMA journal_mode=WAL;", cancellationToken); + await dbContext.Database.ExecuteSqlRawAsync("PRAGMA synchronous=NORMAL;", cancellationToken); + await dbContext.Database.ExecuteSqlRawAsync("PRAGMA busy_timeout=5000;", cancellationToken); + await dbContext.Database.ExecuteSqlRawAsync("PRAGMA cache_size=-64000;", cancellationToken); + var settings = scope.ServiceProvider.GetRequiredService(); await settings.Seed(); await settings.ResetCache();