Skip to content

Commit

Permalink
Revert "Report performance improvements"
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleKayfish authored Aug 30, 2023
1 parent c823898 commit ebce578
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 31 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.FromMinutes(10));
await cache.Set(cacheKey, report, TimeSpan.FromHours(1));
}

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.FromMinutes(10));
await cache.Set(cacheKey, report, TimeSpan.FromHours(1));
}

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)).ToList();
var files = (await QueryEvacuationFiles(readCtx, query, ct)).Concat(await QueryTasks(readCtx, query, ct));

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

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

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)).ToList();
var tasks = (await ((DataServiceQuery<era_task>)taskQuery).GetAllPagesAsync(ct)).ToArray();

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))
.ToList();
.ToArray();

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))
.ToList();
.ToArray();

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);
file.era_era_evacuationfile_era_evacueesupport_ESSFileId = new Collection<era_evacueesupport>(supports.ToArray());
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 10 minutes
.pipe(retry({ delay: 10000, count: 60 }))
// try to get the report for 5 minutes
.pipe(retry({ delay: 6000, count: 50 }))
)
)
.subscribe({
Expand Down
7 changes: 0 additions & 7 deletions shared/src/EMBC.Utilities.Messaging/Grpc/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,11 @@ 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 @@ -144,9 +140,6 @@ 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: 5 additions & 10 deletions shared/src/EMBC.Utilities/Csv/CsvConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,11 @@ private static void CreateRows<T>(IEnumerable<T> list, TextWriter sw, string quo
}
}

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);
private static string Quote(object value, string quoteIdentifier)
{
if (value == null) return string.Empty;
return quoteIdentifier + value + quoteIdentifier;
}

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

0 comments on commit ebce578

Please sign in to comment.