Skip to content

Commit

Permalink
Revert "Revert "Report performance improvements""
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleKayfish authored Sep 21, 2023
1 parent a0474ab commit 0fa4540
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 19 deletions.
6 changes: 3 additions & 3 deletions ess/src/API/EMBC.ESS/Managers/Reports/ReportsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public async Task Handle(EvacueeReportRequested evt)
evacueeQuery.EvacuatedFrom = communities.SingleOrDefault(c => c.Code == evacueeQuery.EvacuatedFrom)?.Name;
evacueeQuery.EvacuatedTo = communities.SingleOrDefault(c => c.Code == evacueeQuery.EvacuatedTo)?.Name;

var csv = evacuees.ToCSV(evacueeQuery);
var csv = evacuees.ToCSV(evacueeQuery, "\"");

var content = Encoding.UTF8.GetBytes(csv);
var contentType = "text/csv";
Expand All @@ -87,7 +87,7 @@ public async Task Handle(EvacueeReportRequested evt)
ContentType = contentType
};
var cacheKey = ReportRequestKey(evt.ReportRequestId);
await cache.Set(cacheKey, report, TimeSpan.FromHours(1));
await cache.Set(cacheKey, report, TimeSpan.FromMinutes(10));
}

public async Task<ReportQueryResult> Handle(EvacueeReportQuery query)
Expand Down Expand Up @@ -147,7 +147,7 @@ public async Task Handle(SupportReportRequested evt)
ContentType = contentType
};
var cacheKey = ReportRequestKey(evt.ReportRequestId);
await cache.Set(cacheKey, report, TimeSpan.FromHours(1));
await cache.Set(cacheKey, report, TimeSpan.FromMinutes(10));
}

public async Task<ReportQueryResult> Handle(SupportReportQuery query)
Expand Down
16 changes: 8 additions & 8 deletions ess/src/API/EMBC.ESS/Resources/Reports/ReportRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public async Task<EvacueeQueryResult> QueryEvacuee(ReportQuery query)
public async Task<SupportQueryResult> QuerySupport(ReportQuery query)
{
var ct = new CancellationTokenSource().Token;
var files = (await QueryEvacuationFiles(readCtx, query, ct)).Concat(await QueryTasks(readCtx, query, ct));
var files = (await QueryEvacuationFiles(readCtx, query, ct)).Concat(await QueryTasks(readCtx, query, ct)).ToList();

var results = await ParallelLoadSupportsAsync(readCtx, files, ct);

Expand All @@ -65,9 +65,9 @@ private static async Task<IEnumerable<era_evacuationfile>> QueryEvacuationFiles(
if (query.StartDate.HasValue) filesQuery = filesQuery.Where(f => f.createdon >= query.StartDate.Value);
if (query.EndDate.HasValue) filesQuery = filesQuery.Where(f => f.createdon <= query.EndDate.Value);

var files = (await ((DataServiceQuery<era_evacuationfile>)filesQuery).GetAllPagesAsync(ct)).ToArray();
if (!string.IsNullOrEmpty(query.TaskNumber)) files = files.Where(f => f.era_TaskId != null && f.era_TaskId.era_name.Equals(query.TaskNumber, StringComparison.OrdinalIgnoreCase)).ToArray();
if (!string.IsNullOrEmpty(query.EvacuatedTo)) files = files.Where(f => f.era_TaskId != null && f.era_TaskId._era_jurisdictionid_value == Guid.Parse(query.EvacuatedTo)).ToArray();
IEnumerable<era_evacuationfile> files = (await ((DataServiceQuery<era_evacuationfile>)filesQuery).GetAllPagesAsync(ct)).ToList();
if (!string.IsNullOrEmpty(query.TaskNumber)) files = files.Where(f => f.era_TaskId != null && f.era_TaskId.era_name.Equals(query.TaskNumber, StringComparison.OrdinalIgnoreCase));
if (!string.IsNullOrEmpty(query.EvacuatedTo)) files = files.Where(f => f.era_TaskId != null && f.era_TaskId._era_jurisdictionid_value == Guid.Parse(query.EvacuatedTo));

return files;
}
Expand All @@ -85,7 +85,7 @@ private static async Task<IEnumerable<era_evacuationfile>> QueryTasks(EssContext
if (!string.IsNullOrEmpty(query.TaskNumber)) taskQuery = taskQuery.Where(f => f.era_name == query.TaskNumber);
if (!string.IsNullOrEmpty(query.EvacuatedTo)) taskQuery = taskQuery.Where(f => f._era_jurisdictionid_value == Guid.Parse(query.EvacuatedTo));

var tasks = (await ((DataServiceQuery<era_task>)taskQuery).GetAllPagesAsync(ct)).ToArray();
var tasks = (await ((DataServiceQuery<era_task>)taskQuery).GetAllPagesAsync(ct)).ToList();

await Parallel.ForEachAsync(tasks, ct, async (t, ct) =>
{
Expand Down Expand Up @@ -123,7 +123,7 @@ private static async Task ParallelLoadEvacueeAsync(EssContext ctx, era_evacuatio
.Expand(m => m.era_Registrant)
.Where(m => m._era_evacuationfileid_value == file.era_evacuationfileid))
.GetAllPagesAsync(ct))
.ToArray();
.ToList();

householdMembers.AsParallel().ForAll(m => m.era_EvacuationFileid = file);
file.era_era_evacuationfile_era_householdmember_EvacuationFileid = new Collection<era_householdmember>(householdMembers);
Expand Down Expand Up @@ -151,15 +151,15 @@ private static async Task ParallelLoadSupportAsync(EssContext ctx, era_evacuatio
.Expand(s => s.era_GroupLodgingCityID)
.Where(s => s._era_evacuationfileid_value == file.era_evacuationfileid))
.GetAllPagesAsync(ct))
.ToArray();
.ToList();

supports.AsParallel().ForAll(s => ctx.AttachTo(nameof(EssContext.era_evacueesupports), s));

loadTasks.AddRange(supports.Select(s => ctx.LoadPropertyAsync(s, nameof(era_evacueesupport.era_era_householdmember_era_evacueesupport), ct)));

await Task.WhenAll(loadTasks);

file.era_era_evacuationfile_era_evacueesupport_ESSFileId = new Collection<era_evacueesupport>(supports.ToArray());
file.era_era_evacuationfile_era_evacueesupport_ESSFileId = new Collection<era_evacueesupport>(supports);
if (file.era_TaskId != null) file.era_TaskId.era_JurisdictionID = ctx.LookupJurisdictionByCode(file.era_TaskId._era_jurisdictionid_value?.ToString());
supports.AsParallel().ForAll(s =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class ReportingComponent implements OnInit, OnDestroy {
private alertService: AlertService,
private locationService: LocationsService,
private customValidation: CustomValidationService
) {}
) { }

ngOnInit(): void {
this.createReportingForm();
Expand Down Expand Up @@ -80,8 +80,8 @@ export class ReportingComponent implements OnInit, OnDestroy {
switchMap((reportId) =>
this.reportService
.reportsGetEvacueeReport({ reportRequestId: reportId })
// try to get the report for 5 minutes
.pipe(retry({ delay: 6000, count: 50 }))
// try to get the report for 10 minutes
.pipe(retry({ delay: 10000, count: 60 }))
)
)
.subscribe({
Expand Down
7 changes: 7 additions & 0 deletions shared/src/EMBC.Utilities.Messaging/Grpc/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@ namespace EMBC.Utilities.Messaging.Grpc
{
public static class Configuration
{
private static readonly int maximumMessageSize = 15 * 1024 * 1024; // 15MB

public static void Configure(ConfigurationServices configurationServices, MessagingOptions options)
{
configurationServices.Services.AddGrpc(opts =>
{
opts.EnableDetailedErrors = configurationServices.Environment.IsDevelopment();
opts.MaxReceiveMessageSize = maximumMessageSize;
opts.MaxSendMessageSize = maximumMessageSize;
});
if (options.Mode == MessagingMode.Server || options.Mode == MessagingMode.Both)
{
Expand Down Expand Up @@ -140,6 +144,9 @@ public static void Configure(ConfigurationServices configurationServices, Messag
return handler;
}).ConfigureChannel(opts =>
{
opts.MaxReceiveMessageSize = maximumMessageSize;
opts.MaxSendMessageSize = maximumMessageSize;
if (options.Url.Scheme == "dns")
{
opts.Credentials = ChannelCredentials.SecureSsl;
Expand Down
15 changes: 10 additions & 5 deletions shared/src/EMBC.Utilities/Csv/CsvConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,16 @@ private static void CreateRows<T>(IEnumerable<T> list, TextWriter sw, string quo
}
}

private static string Quote(object value, string quoteIdentifier)
{
if (value == null) return string.Empty;
return quoteIdentifier + value + quoteIdentifier;
}
private static string Quote(object value, string quoteIdentifier) =>
$"{quoteIdentifier}{Escape(value ?? string.Empty, quoteIdentifier)}{quoteIdentifier}";

private static string Escape(object value, string quoteIdentifier) =>
(quoteIdentifier switch
{
"\"" => value.ToString().Replace("\"", "\"\""),
"'" => value.ToString().Replace("'", "''"),
_ => value.ToString()
}).Replace("\r", string.Empty).Replace("\n", string.Empty);

public static void CreateCSV<T>(this IEnumerable<T> list, string filePath)
{
Expand Down

0 comments on commit 0fa4540

Please sign in to comment.