Skip to content

Commit

Permalink
Fix#32,big log data,sql time out.
Browse files Browse the repository at this point in the history
  • Loading branch information
hayoudotnet committed May 14, 2019
1 parent ca46505 commit 688bda9
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 70 deletions.
32 changes: 16 additions & 16 deletions src/LogDashboard/Handle/DashboardHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,17 @@ public async Task<string> 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<T> 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);
}

Expand All @@ -49,9 +45,13 @@ public async Task<string> GetLogChart(GetChartDataInput input)
return Json(await LogChartFactory.GetLogChart(input.ChartDataType).GetCharts(_logRepository));
}

/// <summary>
/// 获取汇总数据,供首页异步调用
/// </summary>
/// <returns></returns>
public async Task<string> 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);
Expand Down
2 changes: 1 addition & 1 deletion src/LogDashboard/Route/LogDashboardRoutes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ static LogDashboardRoutes()
HtmlView = false
});


// 增加获取汇总数据的路由
Routes.AddRoute(new LogDashboardRoute
{
Key = "/Dashboard/GetLogData",
Expand Down
101 changes: 48 additions & 53 deletions src/LogDashboard/Views/Dashboard/Home.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<div>
<span id="todayCount" class="h4 d-block font-weight-normal mb-2">0</span>
<span class="font-weight-light">今天的日志</span>
</div>
</div>
<div class="h2 text-muted">
<i class="fa fa-external-link-square"></i>
</div>
Expand Down Expand Up @@ -120,27 +120,30 @@
</tr>
</thead>
<tbody class="w-100">
@foreach (var item in Model)
@if (Model != null)
{
<tr class="row mx-0">
<td class="col-1"><a href="javascript:void(0);" onclick="logInfo('@item.Id')">@item.Id</a></td>
<td class="col-3">@item.Logger</td>
<td class="col-1"><button class="btn btn-outline-@item.Level.ToUpper()">@item.Level.ToUpper()</button></td>
<td class="col-4" onclick="$(this).next().show();$(this).css('display', 'none');">
@{
var message = item.Message;
if (message.Length > 90)
{
message = message.Substring(0, 90) + "........";
foreach (var item in Model)
{
<tr class="row mx-0">
<td class="col-1"><a href="javascript:void(0);" onclick="logInfo('@item.Id')">@item.Id</a></td>
<td class="col-3">@item.Logger</td>
<td class="col-1"><button class="btn btn-outline-@item.Level.ToUpper()">@item.Level.ToUpper()</button></td>
<td class="col-4" onclick="$(this).next().show();$(this).css('display', 'none');">
@{
var message = item.Message;
if (message.Length > 90)
{
message = message.Substring(0, 90) + "........";
}
}
}
@message
</td>
<td class="col-4" style="display: none;" onclick="$(this).prev().show();$(this).css('display', 'none');">@item.Message</td>
<td class="col-2">@item.LongDate</td>
<td class="col-1"><a href="javascript:void(0);" onclick="logInfo('@item.Id-info', 'logInfoModal', 'logInfoBody')">详情</a></td>
<div style="display: none" id="@item.Id-info">@item.ToJsonString()</div>
</tr>
@message
</td>
<td class="col-4" style="display: none;" onclick="$(this).prev().show();$(this).css('display', 'none');">@item.Message</td>
<td class="col-2">@item.LongDate</td>
<td class="col-1"><a href="javascript:void(0);" onclick="logInfo('@item.Id-info', 'logInfoModal', 'logInfoBody')">详情</a></td>
<div style="display: none" id="@item.Id-info">@item.ToJsonString()</div>
</tr>
}
}
</tbody>
</table>
Expand Down Expand Up @@ -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({
Expand Down

0 comments on commit 688bda9

Please sign in to comment.