perf(database): Configure SQLite with WAL mode and connection pooling
This commit is contained in:
parent
a7bb8da1d5
commit
47355030b5
2 changed files with 7 additions and 1 deletions
|
|
@ -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<DataContext>(options => options.UseSqlite(connectionString));
|
||||
|
||||
services.AddScoped<DownloadData>();
|
||||
|
|
|
|||
|
|
@ -25,6 +25,12 @@ public class Startup(IServiceProvider serviceProvider) : IHostedService
|
|||
var dbContext = scope.ServiceProvider.GetRequiredService<DataContext>();
|
||||
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<Settings>();
|
||||
await settings.Seed();
|
||||
await settings.ResetCache();
|
||||
|
|
|
|||
Loading…
Reference in a new issue