This commit is contained in:
Roger Far 2026-02-11 20:21:08 -07:00
commit e51e5cde45
5 changed files with 20 additions and 34 deletions

View file

@ -47,8 +47,6 @@ public class DownloadData(DataContext dataContext)
await dataContext.SaveChangesAsync();
await TorrentData.VoidCache();
return download;
}
@ -65,8 +63,6 @@ public class DownloadData(DataContext dataContext)
dbDownload.Link = unrestrictedLink;
await dataContext.SaveChangesAsync();
await TorrentData.VoidCache();
}
public async Task UpdateFileName(Guid downloadId, String fileName)
@ -82,8 +78,6 @@ public class DownloadData(DataContext dataContext)
dbDownload.FileName = fileName;
await dataContext.SaveChangesAsync();
await TorrentData.VoidCache();
}
public async Task UpdateDownloadStarted(Guid downloadId, DateTimeOffset? dateTime)
@ -99,8 +93,6 @@ public class DownloadData(DataContext dataContext)
dbDownload.DownloadStarted = dateTime;
await dataContext.SaveChangesAsync();
await TorrentData.VoidCache();
}
public async Task UpdateDownloadFinished(Guid downloadId, DateTimeOffset? dateTime)
@ -116,8 +108,6 @@ public class DownloadData(DataContext dataContext)
dbDownload.DownloadFinished = dateTime;
await dataContext.SaveChangesAsync();
await TorrentData.VoidCache();
}
public async Task UpdateUnpackingQueued(Guid downloadId, DateTimeOffset? dateTime)
@ -133,8 +123,6 @@ public class DownloadData(DataContext dataContext)
dbDownload.UnpackingQueued = dateTime;
await dataContext.SaveChangesAsync();
await TorrentData.VoidCache();
}
public async Task UpdateUnpackingStarted(Guid downloadId, DateTimeOffset? dateTime)
@ -150,8 +138,6 @@ public class DownloadData(DataContext dataContext)
dbDownload.UnpackingStarted = dateTime;
await dataContext.SaveChangesAsync();
await TorrentData.VoidCache();
}
public async Task UpdateUnpackingFinished(Guid downloadId, DateTimeOffset? dateTime)
@ -167,8 +153,6 @@ public class DownloadData(DataContext dataContext)
dbDownload.UnpackingFinished = dateTime;
await dataContext.SaveChangesAsync();
await TorrentData.VoidCache();
}
public async Task UpdateCompleted(Guid downloadId, DateTimeOffset? dateTime)
@ -184,8 +168,6 @@ public class DownloadData(DataContext dataContext)
dbDownload.Completed = dateTime;
await dataContext.SaveChangesAsync();
await TorrentData.VoidCache();
}
public async Task UpdateError(Guid downloadId, String? error)
@ -201,8 +183,6 @@ public class DownloadData(DataContext dataContext)
dbDownload.Error = error;
await dataContext.SaveChangesAsync();
await TorrentData.VoidCache();
}
public async Task UpdateRetryCount(Guid downloadId, Int32 retryCount)
@ -218,8 +198,6 @@ public class DownloadData(DataContext dataContext)
dbDownload.RetryCount = retryCount;
await dataContext.SaveChangesAsync();
await TorrentData.VoidCache();
}
public async Task UpdateRemoteId(Guid downloadId, String remoteId)
@ -246,8 +224,6 @@ public class DownloadData(DataContext dataContext)
dataContext.Downloads.RemoveRange(downloads);
await dataContext.SaveChangesAsync();
await TorrentData.VoidCache();
}
public async Task Reset(Guid downloadId)
@ -269,7 +245,5 @@ public class DownloadData(DataContext dataContext)
dbDownload.Error = null;
await dataContext.SaveChangesAsync();
await TorrentData.VoidCache();
}
}

View file

@ -17,9 +17,10 @@ public class TorrentData(DataContext dataContext) : ITorrentData
try
{
_torrentCache ??= await dataContext.Torrents
.AsNoTracking()
.Include(m => m.Downloads)
.ToListAsync();
.AsNoTracking()
.AsSplitQuery()
.Include(m => m.Downloads)
.ToListAsync();
return [.. _torrentCache.OrderBy(m => m.Priority ?? 9999).ThenBy(m => m.Added)];
}

View file

@ -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>();

View file

@ -24,6 +24,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();

View file

@ -14,14 +14,15 @@ public class WebsocketsUpdater(ILogger<WebsocketsUpdater> logger, IServiceProvid
await Task.Delay(1000, stoppingToken);
}
var scope = serviceProvider.CreateScope();
var remoteService = scope.ServiceProvider.GetRequiredService<RemoteService>();
logger.LogInformation("WebsocketsUpdater started.");
while (!stoppingToken.IsCancellationRequested)
{
try
{
using var scope = serviceProvider.CreateScope();
var remoteService = scope.ServiceProvider.GetRequiredService<RemoteService>();
await remoteService.Update();
}
catch (Exception ex)
@ -29,7 +30,11 @@ public class WebsocketsUpdater(ILogger<WebsocketsUpdater> logger, IServiceProvid
logger.LogError(ex, $"Unexpected error occurred in WebsocketsUpdater: {ex.Message}");
}
await Task.Delay(TimeSpan.FromSeconds(1), stoppingToken);
var delay = RdtHub.HasConnections
? TimeSpan.FromSeconds(1)
: TimeSpan.FromSeconds(5);
await Task.Delay(delay, stoppingToken);
}
logger.LogInformation("WebsocketsUpdater stopped.");