From ebce57833018e3222c109dfc20fb77668f78f646 Mon Sep 17 00:00:00 2001 From: KyleKayfish <39177955+KyleKayfish@users.noreply.github.com> Date: Wed, 30 Aug 2023 11:25:43 -0700 Subject: [PATCH] Revert "Report performance improvements" --- .../EMBC.ESS/Managers/Reports/ReportsManager.cs | 6 +++--- .../Resources/Reports/ReportRepository.cs | 16 ++++++++-------- .../reporting/reporting.component.ts | 6 +++--- .../Grpc/Configuration.cs | 7 ------- shared/src/EMBC.Utilities/Csv/CsvConverter.cs | 15 +++++---------- 5 files changed, 19 insertions(+), 31 deletions(-) diff --git a/ess/src/API/EMBC.ESS/Managers/Reports/ReportsManager.cs b/ess/src/API/EMBC.ESS/Managers/Reports/ReportsManager.cs index c132e7ede..64dec9839 100644 --- a/ess/src/API/EMBC.ESS/Managers/Reports/ReportsManager.cs +++ b/ess/src/API/EMBC.ESS/Managers/Reports/ReportsManager.cs @@ -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"; @@ -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 Handle(EvacueeReportQuery query) @@ -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 Handle(SupportReportQuery query) diff --git a/ess/src/API/EMBC.ESS/Resources/Reports/ReportRepository.cs b/ess/src/API/EMBC.ESS/Resources/Reports/ReportRepository.cs index b94d6ce04..72c5446bb 100644 --- a/ess/src/API/EMBC.ESS/Resources/Reports/ReportRepository.cs +++ b/ess/src/API/EMBC.ESS/Resources/Reports/ReportRepository.cs @@ -38,7 +38,7 @@ public async Task QueryEvacuee(ReportQuery query) public async Task 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); @@ -65,9 +65,9 @@ private static async Task> 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 files = (await ((DataServiceQuery)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)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; } @@ -85,7 +85,7 @@ private static async Task> 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)taskQuery).GetAllPagesAsync(ct)).ToList(); + var tasks = (await ((DataServiceQuery)taskQuery).GetAllPagesAsync(ct)).ToArray(); await Parallel.ForEachAsync(tasks, ct, async (t, ct) => { @@ -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(householdMembers); @@ -151,7 +151,7 @@ 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)); @@ -159,7 +159,7 @@ private static async Task ParallelLoadSupportAsync(EssContext ctx, era_evacuatio await Task.WhenAll(loadTasks); - file.era_era_evacuationfile_era_evacueesupport_ESSFileId = new Collection(supports); + file.era_era_evacuationfile_era_evacueesupport_ESSFileId = new Collection(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 => { diff --git a/responders/src/UI/embc-responder/src/app/feature-components/reporting/reporting.component.ts b/responders/src/UI/embc-responder/src/app/feature-components/reporting/reporting.component.ts index b546f8dbb..0b7bc086b 100644 --- a/responders/src/UI/embc-responder/src/app/feature-components/reporting/reporting.component.ts +++ b/responders/src/UI/embc-responder/src/app/feature-components/reporting/reporting.component.ts @@ -38,7 +38,7 @@ export class ReportingComponent implements OnInit, OnDestroy { private alertService: AlertService, private locationService: LocationsService, private customValidation: CustomValidationService - ) { } + ) {} ngOnInit(): void { this.createReportingForm(); @@ -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({ diff --git a/shared/src/EMBC.Utilities.Messaging/Grpc/Configuration.cs b/shared/src/EMBC.Utilities.Messaging/Grpc/Configuration.cs index 6a2921ccd..72d59bc28 100644 --- a/shared/src/EMBC.Utilities.Messaging/Grpc/Configuration.cs +++ b/shared/src/EMBC.Utilities.Messaging/Grpc/Configuration.cs @@ -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) { @@ -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; diff --git a/shared/src/EMBC.Utilities/Csv/CsvConverter.cs b/shared/src/EMBC.Utilities/Csv/CsvConverter.cs index 784b6073b..385ccffb9 100644 --- a/shared/src/EMBC.Utilities/Csv/CsvConverter.cs +++ b/shared/src/EMBC.Utilities/Csv/CsvConverter.cs @@ -35,16 +35,11 @@ private static void CreateRows(IEnumerable 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(this IEnumerable list, string filePath) {