From 688bda94d34c570faeeb75fa0f69fdb1648bd943 Mon Sep 17 00:00:00 2001 From: Jun Date: Wed, 15 May 2019 07:21:59 +0800 Subject: [PATCH] Fix#32,big log data,sql time out. --- src/LogDashboard/Handle/DashboardHandle.cs | 32 +++--- src/LogDashboard/Route/LogDashboardRoutes.cs | 2 +- src/LogDashboard/Views/Dashboard/Home.cshtml | 101 +++++++++---------- 3 files changed, 65 insertions(+), 70 deletions(-) diff --git a/src/LogDashboard/Handle/DashboardHandle.cs b/src/LogDashboard/Handle/DashboardHandle.cs index d11541b..8dcca09 100644 --- a/src/LogDashboard/Handle/DashboardHandle.cs +++ b/src/LogDashboard/Handle/DashboardHandle.cs @@ -26,21 +26,17 @@ public async Task Home() { ViewBag.dashboardNav = "active"; ViewBag.basicLogNav = ""; - var result = await _logRepository.GetPageListAsync(1, 10, sorts: new[] { new Sort { Ascending = false, PropertyName = "Id" } }); - - //ViewBag.unique = (await _logRepository.UniqueCountAsync()).Count; - - //var now = DateTime.Now; - //var weeHours = now.Date.AddHours(23).AddMinutes(59).AddSeconds(59); - //ViewBag.todayCount = await _logRepository.CountAsync(x => x.LongDate >= now.Date && x.LongDate <= weeHours); - - //var hour = now.AddHours(-1); - //ViewBag.hourCount = await _logRepository.CountAsync(x => x.LongDate >= hour && x.LongDate <= now); - //ViewBag.allCount = await _logRepository.CountAsync(); - - ////Chart Data - //ViewBag.ChartData = (await LogChartFactory.GetLogChart(ChartDataType.Hour).GetCharts(_logRepository)).ToJsonString(); - + IEnumerable result = null; + try + { + result = await _logRepository.GetPageListAsync(1, 10, sorts: new[] { new Sort { Ascending = false, PropertyName = "Id" } }); + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + //throw ex; + } + return await View(result); } @@ -49,9 +45,13 @@ public async Task GetLogChart(GetChartDataInput input) return Json(await LogChartFactory.GetLogChart(input.ChartDataType).GetCharts(_logRepository)); } + /// + /// 获取汇总数据,供首页异步调用 + /// + /// public async Task GetLogData() { - var unique = 0;// (await _logRepository.UniqueCountAsync()).Count; // 当数据量较大时,该方法将会超时,导致首页无法运行 + var unique = 0;// (await _logRepository.UniqueCountAsync()).Count; // 当数据量较大时,该方法()将会超时,导致首页无法运行 var now = DateTime.Now; var weeHours = now.Date.AddHours(23).AddMinutes(59).AddSeconds(59); var todayCount = await _logRepository.CountAsync(x => x.LongDate >= now.Date && x.LongDate <= weeHours); diff --git a/src/LogDashboard/Route/LogDashboardRoutes.cs b/src/LogDashboard/Route/LogDashboardRoutes.cs index c39a2ef..1e983e1 100644 --- a/src/LogDashboard/Route/LogDashboardRoutes.cs +++ b/src/LogDashboard/Route/LogDashboardRoutes.cs @@ -36,7 +36,7 @@ static LogDashboardRoutes() HtmlView = false }); - + // 增加获取汇总数据的路由 Routes.AddRoute(new LogDashboardRoute { Key = "/Dashboard/GetLogData", diff --git a/src/LogDashboard/Views/Dashboard/Home.cshtml b/src/LogDashboard/Views/Dashboard/Home.cshtml index 005b541..a68b1aa 100644 --- a/src/LogDashboard/Views/Dashboard/Home.cshtml +++ b/src/LogDashboard/Views/Dashboard/Home.cshtml @@ -37,7 +37,7 @@
0 今天的日志 -
+
@@ -120,27 +120,30 @@ - @foreach (var item in Model) + @if (Model != null) { - - @item.Id - @item.Logger - - - @{ - var message = item.Message; - if (message.Length > 90) - { - message = message.Substring(0, 90) + "........"; + foreach (var item in Model) + { + + @item.Id + @item.Logger + + + @{ + var message = item.Message; + if (message.Length > 90) + { + message = message.Substring(0, 90) + "........"; + } } - } - @message - - @item.Message - @item.LongDate - 详情 - - + @message + + @item.Message + @item.LongDate + 详情 + + + } } @@ -198,44 +201,36 @@ ]; - @*$(function() { - - var output = JSON.parse('@Raw(ViewBag.ChartData)'); - charts[0].all = output.All; - charts[0].error = output.Error; - initLineChart(charts[0]); - });*@ - - $(function () { + $(function () { + getLogTotal(); + getLogChart(1); + setInterval(() => { getLogTotal(); getLogChart(1); - setInterval(() => { - getLogTotal(); - getLogChart(1); - }, 10000); + }, 10000); - setTimeout(() => { - getLogChart(2); - getLogChart(3); - getLogChart(4); - } - , 5000); - }); - - function getLogTotal() { + setTimeout(() => { + getLogChart(2); + getLogChart(3); + getLogChart(4); + } + , 5000); + }); + //异步获取数据 + function getLogTotal() { - $.ajax({ - method: "POST", - url: mapPath + "/Dashboard/GetLogData", - data: {} - }).done(function (data) { - if (data) { - for (var itm in data) { - $("#" + itm).text(data[itm]); - } + $.ajax({ + method: "POST", + url: mapPath + "/Dashboard/GetLogData", + data: {} + }).done(function (data) { + if (data) { + for (var itm in data) { + $("#" + itm).text(data[itm]); } - }); - } + } + }); + } function getLogChart(i) { $.ajax({