Skip to content

Commit

Permalink
减少TraceItem数据量较大时的性能浪费
Browse files Browse the repository at this point in the history
  • Loading branch information
nnhy committed Oct 22, 2024
1 parent 2b241e1 commit ea51b3b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
7 changes: 4 additions & 3 deletions Stardust.Data/Monitors/应用跟踪器.Biz.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public override void Valid(Boolean isNew)
}
else
{
ItemCount = TraceItems.Count;
ItemCount = TraceItem.FindCountByApp(ID);
}
}

Expand All @@ -97,7 +97,7 @@ public override void Valid(Boolean isNew)
/// 有效跟踪项集合
/// </summary>
[XmlIgnore, IgnoreDataMember]
public IList<TraceItem> TraceItems => Extends.Get(nameof(TraceItems), k => TraceItem.GetValids(ID, DateTime.Today.AddDays(-30)));
public IList<TraceItem> TraceItems => Extends.Get(nameof(TraceItems), k => TraceItem.GetValids(ID, DateTime.Today.AddDays(-3)));
#endregion

#region 扩展查询
Expand Down Expand Up @@ -369,7 +369,8 @@ public void Fix()
Days = list.Select(e => e.StatDate.ToFullString()).Distinct().Count();
Total = list.Sum(e => (Int64)e.Total);

ItemCount = TraceItems.Count;
//ItemCount = TraceItems.Count;
ItemCount = TraceItem.FindCountByApp(ID);
}
#endregion
}
7 changes: 7 additions & 0 deletions Stardust.Data/Monitors/跟踪项.Biz.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ public static IList<TraceItem> FindAllByApp(Int32 appId)
return FindAll(_.AppId == appId);
}

public static Int32 FindCountByApp(Int32 appId)
{
if (appId <= 0) return 0;

return (Int32)FindCount(_.AppId == appId);
}

/// <summary>根据应用、操作名查找</summary>
/// <param name="appId">应用</param>
/// <param name="name">操作名</param>
Expand Down
3 changes: 2 additions & 1 deletion Stardust.Server/Controllers/TraceController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public TraceResponse Report([FromBody] TraceModel model, String token)
var (app, online) = Valid(model.AppId, model, model.ClientId, ip, token);

// 插入数据
if (builders != null && builders.Length > 0) Task.Run(() => ProcessData(app, model, online?.NodeId ?? 0, ip, builders));
//if (builders != null && builders.Length > 0) Task.Run(() => ProcessData(app, model, online?.NodeId ?? 0, ip, builders));
if (builders != null && builders.Length > 0) ProcessData(app, model, online?.NodeId ?? 0, ip, builders);

// 构造响应
var rs = new TraceResponse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,8 @@ public ActionResult FixOldData()
}
}

app.ItemCount = app.TraceItems.Count;
//app.ItemCount = app.TraceItems.Count;
app.ItemCount = TraceItem.FindCountByApp(app.ID);
app.Update();
}
}
Expand Down

0 comments on commit ea51b3b

Please sign in to comment.