From 4ac8dbc060874083429973ebe245c4d848fc172f Mon Sep 17 00:00:00 2001 From: Vitalii Mikhailov Date: Mon, 27 May 2024 22:48:59 +0300 Subject: [PATCH] Fixed UnitOfWrite reusage Added indication of invalid archive parsing --- .../Jobs/NexusModsModFileUpdatesProcessorJob.cs | 2 +- src/BUTR.Site.NexusMods.Server/Repositories/IUnitOfWrite.cs | 4 ++-- .../Services/General/INexusModsModFileParser.cs | 2 ++ src/BUTR.Site.NexusMods.Server/Startup.cs | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/BUTR.Site.NexusMods.Server/Jobs/NexusModsModFileUpdatesProcessorJob.cs b/src/BUTR.Site.NexusMods.Server/Jobs/NexusModsModFileUpdatesProcessorJob.cs index 0bb2d3e6..e05a9ead 100644 --- a/src/BUTR.Site.NexusMods.Server/Jobs/NexusModsModFileUpdatesProcessorJob.cs +++ b/src/BUTR.Site.NexusMods.Server/Jobs/NexusModsModFileUpdatesProcessorJob.cs @@ -79,7 +79,7 @@ public async Task Execute(IJobExecutionContext context) var gameDomain = tenant.ToGameDomain(); - var dateOneWeekAgo = DateTime.UtcNow.AddDays(-30); + var dateOneWeekAgo = DateTime.UtcNow.AddDays(-7); var updatesStoredWithinWeek = await unitOfRead.NexusModsModToFileUpdates.GetAllAsync(x => x.LastCheckedDate > dateOneWeekAgo, null, ct); var updatedWithinWeek = await _nexusModsAPIClient.GetAllModUpdatesWeekAsync(gameDomain, _nexusModsOptions.ApiKey, ct) ?? Array.Empty(); var newUpdates = updatedWithinWeek.Where(x => diff --git a/src/BUTR.Site.NexusMods.Server/Repositories/IUnitOfWrite.cs b/src/BUTR.Site.NexusMods.Server/Repositories/IUnitOfWrite.cs index 8af011bf..3a42d3b6 100644 --- a/src/BUTR.Site.NexusMods.Server/Repositories/IUnitOfWrite.cs +++ b/src/BUTR.Site.NexusMods.Server/Repositories/IUnitOfWrite.cs @@ -66,7 +66,7 @@ internal class UnitOfWrite : IUnitOfWrite private IDbContextTransaction _dbContextTransaction; - public UpsertEntityFactory UpsertEntityFactory { get; } + public UpsertEntityFactory UpsertEntityFactory { get; private set; } public IAutocompleteEntityRepositoryWrite Autocompletes { get; } @@ -117,7 +117,6 @@ public UnitOfWrite(IServiceProvider serviceProvider) dbContextProvider.Set(_dbContext); _dbContextTransaction = _dbContext.Database.BeginTransaction(); - UpsertEntityFactory = _dbContext.GetEntityFactory(); Autocompletes = ActivatorUtilities.CreateInstance(serviceProvider, dbContextProvider); @@ -168,6 +167,7 @@ public async Task SaveChangesAsync(CancellationToken ct) await _dbContext.SaveAsync(ct); await _dbContextTransaction.CommitAsync(ct); _dbContextTransaction = _dbContext.Database.BeginTransaction(); + UpsertEntityFactory = _dbContext.GetEntityFactory(); } catch (Exception e) { diff --git a/src/BUTR.Site.NexusMods.Server/Services/General/INexusModsModFileParser.cs b/src/BUTR.Site.NexusMods.Server/Services/General/INexusModsModFileParser.cs index dbe8dc29..0f2c897d 100644 --- a/src/BUTR.Site.NexusMods.Server/Services/General/INexusModsModFileParser.cs +++ b/src/BUTR.Site.NexusMods.Server/Services/General/INexusModsModFileParser.cs @@ -114,6 +114,8 @@ public async IAsyncEnumerable GetModuleInfosAsync( httpStream.SetBufferSize(LargeBufferSize); var moduleInfosArchive = await GetModuleInfosFromArchiveAsync(archive, subModuleCount).ToListAsync(ct); + if (moduleInfosArchive.Count != subModuleCount) throw new InvalidOperationException($"Failed to get all ModuleInfos for file '{fileInfo.FileName}'"); + var dataArchive = await GetGameVersionsFromArchiveAsync(archive, moduleInfosArchive).ToListAsync(ct); foreach (var grouping in dataArchive.GroupBy(x => new { x.Item1.Id, x.Item1.Version })) { diff --git a/src/BUTR.Site.NexusMods.Server/Startup.cs b/src/BUTR.Site.NexusMods.Server/Startup.cs index b9b73a05..f1db615e 100644 --- a/src/BUTR.Site.NexusMods.Server/Startup.cs +++ b/src/BUTR.Site.NexusMods.Server/Startup.cs @@ -234,7 +234,7 @@ public void ConfigureServices(IServiceCollection services) services.AddMemoryCache(); - + var types = typeof(Startup).Assembly.GetTypes().Where(x => x is { IsAbstract: false, BaseType: { IsGenericType: true } }).ToList(); foreach (var type in types.Where(x => x.BaseType!.GetGenericTypeDefinition() == typeof(BaseEntityConfigurationWithTenant<>))) services.TryAddEnumerable(ServiceDescriptor.Scoped(typeof(IEntityConfiguration), type));