From 04062df1e1a1da31d08afc43ad0e3683db4606a0 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Wed, 29 Dec 2021 19:35:41 +0000 Subject: [PATCH] --- .vscode/launch.json | 4 +-- server/AyaNova/biz/PMBiz.cs | 2 ++ server/AyaNova/biz/QuoteBiz.cs | 2 ++ server/AyaNova/biz/ReportBiz.cs | 43 +++++++++++++++++++----------- server/AyaNova/biz/WorkOrderBiz.cs | 8 +++--- server/AyaNova/util/ObjectCache.cs | 4 +++ server/AyaNova/util/VizCache.cs | 4 +++ 7 files changed, 45 insertions(+), 22 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index fb432ce8..58d9463f 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -48,8 +48,8 @@ "AYANOVA_DATA_PATH": "c:\\temp\\ravendata", "AYANOVA_USE_URLS": "http://*:7575;", "AYANOVA_SERVER_TEST_MODE": "false", - //"AYANOVA_REPORT_RENDERING_TIMEOUT":"19", - "AYANOVA_SERVER_TEST_MODE_SEEDLEVEL": "small", + "AYANOVA_REPORT_RENDERING_TIMEOUT":"60", + "AYANOVA_SERVER_TEST_MODE_SEEDLEVEL": "large", "AYANOVA_BACKUP_PG_DUMP_PATH": "C:\\data\\code\\postgres_14\\bin\\" }, "sourceFileMap": { diff --git a/server/AyaNova/biz/PMBiz.cs b/server/AyaNova/biz/PMBiz.cs index 510117dd..b33a266e 100644 --- a/server/AyaNova/biz/PMBiz.cs +++ b/server/AyaNova/biz/PMBiz.cs @@ -856,6 +856,8 @@ namespace AyaNova.Biz ReportData.Add(jo); } } + vc.Clear(); + oc.Clear(); return ReportData; } diff --git a/server/AyaNova/biz/QuoteBiz.cs b/server/AyaNova/biz/QuoteBiz.cs index b4741757..18ddd5de 100644 --- a/server/AyaNova/biz/QuoteBiz.cs +++ b/server/AyaNova/biz/QuoteBiz.cs @@ -832,6 +832,8 @@ namespace AyaNova.Biz ReportData.Add(jo); } } + vc.Clear(); + oc.Clear(); return ReportData; } diff --git a/server/AyaNova/biz/ReportBiz.cs b/server/AyaNova/biz/ReportBiz.cs index f2346d8a..ac76e008 100644 --- a/server/AyaNova/biz/ReportBiz.cs +++ b/server/AyaNova/biz/ReportBiz.cs @@ -381,7 +381,7 @@ namespace AyaNova.Biz AuthorizationRoles effectiveRoles = CurrentUserRoles; - + if (!RequestIsCustomerWorkOrderReport && !AyaNova.Api.ControllerHelpers.Authorized.HasReadFullRole(effectiveRoles, report.AType)) { log.LogDebug($"bail: user unauthorized"); @@ -490,7 +490,12 @@ namespace AyaNova.Biz var ReportJSFolderPath = Path.Combine(ServerBootConfig.AYANOVA_CONTENT_ROOT_PATH, "resource", "rpt"); + + //Keep for debugging headfully + //var lo = new LaunchOptions { Headless = false }; var lo = new LaunchOptions { Headless = true }; + + if (!AutoDownloadChromium) { lo.ExecutablePath = ServerBootConfig.AYANOVA_REPORT_RENDER_BROWSER_PATH; @@ -511,10 +516,7 @@ namespace AyaNova.Biz */ } else - { - // #if (DEBUG) - // log.LogInformation($"DBG: ReportBiz::calling browserfetcher"); - // #endif + { log.LogDebug($"Windows: Calling browserFetcher download async now:"); await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultChromiumRevision); } @@ -524,7 +526,13 @@ namespace AyaNova.Biz //*** DANGER: --disable-dev-shm-usage will crash linux ayanova when it runs out of memory **** //that was only suitable for dockerized scenario as it had an alt swap system //var OriginalDefaultArgs = "--disable-dev-shm-usage --single-process --no-sandbox --disable-gpu --no-zygote "; + + + + //Keep for debugging headfully + // var DefaultArgs = "--no-sandbox"; var DefaultArgs = "--headless --no-sandbox"; + if (!string.IsNullOrWhiteSpace(ServerBootConfig.AYANOVA_REPORT_RENDER_BROWSER_PARAMS)) { log.LogDebug($"AYANOVA_REPORT_RENDER_BROWSER_PARAMS will be used: {ServerBootConfig.AYANOVA_REPORT_RENDER_BROWSER_PARAMS}"); @@ -615,8 +623,8 @@ namespace AyaNova.Biz if (!string.IsNullOrWhiteSpace(report.JsHelpers)) await page.AddScriptTagAsync(new AddTagOptions() { Content = report.JsHelpers }); - if (!string.IsNullOrWhiteSpace(report.Style)) - await page.AddStyleTagAsync(new AddTagOptions() { Content = report.Style }); + // if (!string.IsNullOrWhiteSpace(report.Style)) + // await page.AddStyleTagAsync(new AddTagOptions() { Content = report.Style }); log.LogDebug($"Preparing page: adding Client meta data"); @@ -682,17 +690,20 @@ namespace AyaNova.Biz var compiledHTML = await page.EvaluateExpressionAsync(compileScript); if (!ReportRenderManager.KeepGoing(job.GId)) return; + //render report as HTML - log.LogDebug($"Setting page content to compiled HTML"); - await page.SetContentAsync(compiledHTML); + //add style + // if (!string.IsNullOrWhiteSpace(report.Style)) + // { + // log.LogDebug($"Adding report template Style CSS"); + // await page.AddStyleTagAsync(new AddTagOptions { Content = report.Style }); + // } + // log.LogInformation(report.Style); + // log.LogInformation(compiledHTML); + log.LogDebug($"Setting page content to style and compiled HTML"); + await page.SetContentAsync($"{compiledHTML}"); - //add style (after page or it won't work) - if (!string.IsNullOrWhiteSpace(report.Style)) - { - log.LogDebug($"Adding report template Style CSS"); - await page.AddStyleTagAsync(new AddTagOptions { Content = report.Style }); - } string outputFileName = StringUtil.ReplaceLastOccurrence(FileUtil.NewRandomFileName, ".", "") + ".pdf"; string outputFullPath = System.IO.Path.Combine(FileUtil.TemporaryFilesFolder, outputFileName); @@ -779,7 +790,7 @@ namespace AyaNova.Biz return; //render to pdf and return log.LogDebug($"Calling render page contents to PDF"); - await page.PdfAsync(outputFullPath, PdfOptions);//###### TODO: SLOW NEEDS TIMEOUT HERE ONCE SUPPORTED, open bug: https://github.com/hardkoded/puppeteer-sharp/issues/1710 + await page.PdfAsync(outputFullPath, PdfOptions); log.LogDebug($"Closing Page"); await page.CloseAsync(); diff --git a/server/AyaNova/biz/WorkOrderBiz.cs b/server/AyaNova/biz/WorkOrderBiz.cs index 3862234c..dd85b966 100644 --- a/server/AyaNova/biz/WorkOrderBiz.cs +++ b/server/AyaNova/biz/WorkOrderBiz.cs @@ -986,11 +986,11 @@ namespace AyaNova.Biz } ReportData.Add(jo); } + batchResults.Clear(); } - // #if (DEBUG) - // watch.Stop(); - // System.Diagnostics.Debug.WriteLine($"Workorderbiz::GetReportData took ms: {watch.ElapsedMilliseconds}"); - // #endif + + vc.Clear(); + oc.Clear(); return ReportData; } diff --git a/server/AyaNova/util/ObjectCache.cs b/server/AyaNova/util/ObjectCache.cs index c388adf6..c410c776 100644 --- a/server/AyaNova/util/ObjectCache.cs +++ b/server/AyaNova/util/ObjectCache.cs @@ -12,6 +12,10 @@ namespace AyaNova.Util // { // System.Diagnostics.Debug.WriteLine("constructing objectcache"); // } + internal void Clear() + { + _cache.Clear(); + } internal void Add(object value, string key, long? id = 0) { diff --git a/server/AyaNova/util/VizCache.cs b/server/AyaNova/util/VizCache.cs index 94a4a627..dded2b53 100644 --- a/server/AyaNova/util/VizCache.cs +++ b/server/AyaNova/util/VizCache.cs @@ -12,6 +12,10 @@ namespace AyaNova.Util // { // System.Diagnostics.Debug.WriteLine("constructing vizcache"); // } + internal void Clear() + { + _vizCache.Clear(); + } internal void Add(string value, string key, long? id = 0) { if (value == null) value = string.Empty;