Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Aragas committed Oct 2, 2023
1 parent 6f3e20d commit ae228f7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
6 changes: 1 addition & 5 deletions src/BUTR.Site.NexusMods.Client/Models/DemoUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
using BUTR.Site.NexusMods.ServerClient;
using BUTR.Site.NexusMods.Shared.Helpers;

using HtmlAgilityPack;

using System;
using System.Collections.Generic;
using System.Collections.Immutable;
Expand Down Expand Up @@ -50,9 +48,7 @@ static string GetException(ExceptionModel? exception, bool inner = false) => exc
var response = await client.SendAsync(request);
var content = await response.Content.ReadAsStringAsync();

var document = new HtmlDocument();
document.LoadHtml(content.Replace("<filename unknown>", "NULL"));
return (id, CrashReportParser.ParseLegacyHtml(10, document, content));
return (id, CrashReportParser.ParseLegacyHtml(10, content));
}

if (_crashReports is null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
<PackageReference Include="butr.crashreport.bannerlord.parser" Version="13.0.0.14" />
<PackageReference Include="Community.Microsoft.Extensions.Caching.PostgreSql" Version="4.0.4" />
<PackageReference Include="DynamicExpressions.NET" Version="1.1.0" />
<PackageReference Include="HtmlAgilityPack" Version="1.11.53" />
<PackageReference Include="ICSharpCode.Decompiler" Version="8.1.1.7464" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.5.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.0-rc.1.23419.6" PrivateAssets="all" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
Expand Down
20 changes: 13 additions & 7 deletions src/BUTR.Site.NexusMods.Server/Jobs/CrashReportProcessorJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public CrashReportProcessorJob(ILogger<CrashReportProcessorJob> logger, IService
_serviceScopeFactory = serviceScopeFactory ?? throw new ArgumentNullException(nameof(serviceScopeFactory));
}

private static async Task DownloadCrashReportsAsync(TenantId tenant, IAsyncEnumerable<CrashReportFileMetadata> requests, CrashReporterClient client, ChannelWriter<HttpResultEntry> httpResultChannel, CancellationToken ct)
private static async Task DownloadCrashReportsAsync(TenantId tenant, IAsyncEnumerable<CrashReportFileMetadata> requests, ILogger logger, CrashReporterClient client, ChannelWriter<HttpResultEntry> httpResultChannel, CancellationToken ct)
{
var options = new ParallelOptions { CancellationToken = ct, MaxDegreeOfParallelism = ParallelCount };
await Parallel.ForEachAsync(requests, options, async (entry, ct2) =>
Expand All @@ -70,9 +70,15 @@ await Parallel.ForEachAsync(requests, options, async (entry, ct2) =>
{
var content = await client.GetCrashReportAsync(fileId, ct2);

var document = new HtmlDocument();
document.LoadHtml(content.Replace("<filename unknown>", "NULL"));
model = CrashReportParser.ParseLegacyHtml(version, document, content);
try
{
model = CrashReportParser.ParseLegacyHtml(version, content);
}
catch (Exception e)
{
logger.LogError(e, "Failed to parse {FileId}", fileId);
throw;
}
}
else
{
Expand Down Expand Up @@ -253,7 +259,7 @@ static string GetException(ExceptionModel? exception, bool inner = false) => exc
// Disposing the DBContext will save the data
}

private static async Task HandleFileIdDatesAsync(TenantId tenant, IServiceProvider serviceProvider, CrashReporterClient client, IAsyncEnumerable<CrashReportFileMetadata> requests, CancellationToken ct)
private static async Task HandleFileIdDatesAsync(TenantId tenant, IServiceProvider serviceProvider, ILogger logger, CrashReporterClient client, IAsyncEnumerable<CrashReportFileMetadata> requests, CancellationToken ct)
{
var options = serviceProvider.GetRequiredService<IOptions<CrashReporterOptions>>().Value;
var httpResultChannel = Channel.CreateBounded<HttpResultEntry>(ParallelCount);
Expand All @@ -263,7 +269,7 @@ private static async Task HandleFileIdDatesAsync(TenantId tenant, IServiceProvid

await Task.WhenAll(new Task[]
{
DownloadCrashReportsAsync(tenant, requests, client, httpResultChannel, ct),
DownloadCrashReportsAsync(tenant, requests, logger, client, httpResultChannel, ct),
FilterCrashReportsAsync(tenant, serviceProvider, httpResultChannel, databaseResultChannel, linkedCrashReportsChannel, ignoredCrashReportsChannel, ct),
WriteIgnoredToDatabaseAsync(tenant, serviceProvider, ignoredCrashReportsChannel, ct),
WriteLinkedToDatabaseAsync(tenant, serviceProvider, linkedCrashReportsChannel, ct),
Expand Down Expand Up @@ -301,7 +307,7 @@ public async Task Execute(IJobExecutionContext context)
fileIds.ExceptWith(await dbContextRead.CrashReportToFileIds.Where(x => fileIds.Contains(x.FileId)).Select(x => x.FileId).ToListAsync(ct));
if (fileIds.Count == 0) continue;

await HandleFileIdDatesAsync(tenant, scope.ServiceProvider, client, client.GetCrashReportMetadataAsync(fileIds, ct).OfType<CrashReportFileMetadata>(), ct);
await HandleFileIdDatesAsync(tenant, scope.ServiceProvider, _logger, client, client.GetCrashReportMetadataAsync(fileIds, ct).OfType<CrashReportFileMetadata>(), ct);
processed += fileIds.Count;
}
}
Expand Down

0 comments on commit ae228f7

Please sign in to comment.