NewLife/Stardust

减少TraceItem数据量较大时的性能浪费
智能大石头 authored at 2024-10-22 08:41:14
ea51b3b
Tree
1 Parent(s) 2b241e1
Summary: 4 changed files with 15 additions and 5 deletions.
Modified +4 -3
Modified +7 -0
Modified +2 -1
Modified +2 -1
Modified +4 -3
diff --git "a/Stardust.Data/Monitors/\345\272\224\347\224\250\350\267\237\350\270\252\345\231\250.Biz.cs" "b/Stardust.Data/Monitors/\345\272\224\347\224\250\350\267\237\350\270\252\345\231\250.Biz.cs"
index 19f2266..346113c 100644
--- "a/Stardust.Data/Monitors/\345\272\224\347\224\250\350\267\237\350\270\252\345\231\250.Biz.cs"
+++ "b/Stardust.Data/Monitors/\345\272\224\347\224\250\350\267\237\350\270\252\345\231\250.Biz.cs"
@@ -75,7 +75,7 @@ public partial class AppTracer : Entity<AppTracer>
         }
         else
         {
-            ItemCount = TraceItems.Count;
+            ItemCount = TraceItem.FindCountByApp(ID);
         }
     }
 
@@ -97,7 +97,7 @@ public partial class AppTracer : Entity<AppTracer>
     /// 有效跟踪项集合
     /// </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 扩展查询
@@ -369,7 +369,8 @@ public partial class AppTracer : Entity<AppTracer>
         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
 }
\ No newline at end of file
Modified +7 -0
diff --git "a/Stardust.Data/Monitors/\350\267\237\350\270\252\351\241\271.Biz.cs" "b/Stardust.Data/Monitors/\350\267\237\350\270\252\351\241\271.Biz.cs"
index 93b6218..9c86890 100644
--- "a/Stardust.Data/Monitors/\350\267\237\350\270\252\351\241\271.Biz.cs"
+++ "b/Stardust.Data/Monitors/\350\267\237\350\270\252\351\241\271.Biz.cs"
@@ -96,6 +96,13 @@ public partial class TraceItem : Entity<TraceItem>
         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>
Modified +2 -1
diff --git a/Stardust.Server/Controllers/TraceController.cs b/Stardust.Server/Controllers/TraceController.cs
index 3c346cb..0e1a6d4 100644
--- a/Stardust.Server/Controllers/TraceController.cs
+++ b/Stardust.Server/Controllers/TraceController.cs
@@ -54,7 +54,8 @@ public class TraceController : ControllerBase
         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
Modified +2 -1
diff --git a/Stardust.Web/Areas/Monitors/Controllers/AppTracerController.cs b/Stardust.Web/Areas/Monitors/Controllers/AppTracerController.cs
index 484238c..9ba37f3 100644
--- a/Stardust.Web/Areas/Monitors/Controllers/AppTracerController.cs
+++ b/Stardust.Web/Areas/Monitors/Controllers/AppTracerController.cs
@@ -280,7 +280,8 @@ public class AppTracerController : EntityController<AppTracer>
                     }
                 }
 
-                app.ItemCount = app.TraceItems.Count;
+                //app.ItemCount = app.TraceItems.Count;
+                app.ItemCount = TraceItem.FindCountByApp(app.ID);
                 app.Update();
             }
         }