懒得勤快 3 éve
szülő
commit
70c758c5a4

+ 1 - 3
src/Masuit.MyBlogs.Core/Common/PerfCounter.cs

@@ -4,7 +4,6 @@ using Masuit.Tools.DateTimeExt;
 using Masuit.Tools.Hardware;
 using Masuit.Tools.Logging;
 using Masuit.Tools.Systems;
-using Microsoft.EntityFrameworkCore;
 using Microsoft.Extensions.DependencyInjection.Extensions;
 using System.ComponentModel.DataAnnotations;
 using System.ComponentModel.DataAnnotations.Schema;
@@ -124,8 +123,7 @@ public class PerfCounterInDatabase : IPerfCounter
         if (_dbContext.SaveChanges() > 0)
         {
             var start = DateTime.Now.AddMonths(-1).GetTotalMilliseconds();
-            var tableName = _dbContext.Model.FindEntityType(typeof(PerformanceCounter)).GetTableName();
-            _dbContext.Database.ExecuteSqlRaw($"DELETE FROM \"{tableName}\" WHERE \"{nameof(PerformanceCounter.Time)}\" <{start}");
+            _dbContext.Set<PerformanceCounter>().Where(e => e.Time < start).DeleteFromQuery();
         }
     }
 }

+ 1 - 3
src/Masuit.MyBlogs.Core/Extensions/Firewall/IRequestLogger.cs

@@ -2,7 +2,6 @@
 using Masuit.MyBlogs.Core.Infrastructure;
 using Masuit.MyBlogs.Core.Models.Entity;
 using Masuit.Tools;
-using Microsoft.EntityFrameworkCore;
 using Microsoft.Extensions.DependencyInjection.Extensions;
 using System.Collections.Concurrent;
 using System.Diagnostics;
@@ -92,8 +91,7 @@ public class RequestDatabaseLogger : IRequestLogger
         if (_dataContext.SaveChanges() > 0)
         {
             var start = DateTime.Now.AddMonths(-6);
-            var tableName = _dataContext.Model.FindEntityType(typeof(RequestLogDetail)).GetTableName();
-            _dataContext.Database.ExecuteSqlRaw($"DELETE FROM \"{tableName}\" WHERE \"{nameof(RequestLogDetail.Time)}\" <'{start:yyyy-MM-dd HH:mm:ss}'");
+            _dataContext.Set<RequestLogDetail>().Where(e => e.Time < start).DeleteFromQuery();
         }
     }
 }

+ 1 - 1
src/Masuit.MyBlogs.Core/Infrastructure/LoggerDbContext.cs

@@ -18,7 +18,7 @@ public class LoggerDbContext : DbContext
     protected override void OnModelCreating(ModelBuilder modelBuilder)
     {
         modelBuilder.Entity<RequestLogDetail>().HasKey(e => new { e.Id, e.Time });
-        modelBuilder.Entity<PerformanceCounter>().HasKey(e => e.Time);
+        modelBuilder.Entity<PerformanceCounter>().HasKey(e => new { e.ServerIP, e.Time });
     }
 }