懒得勤快 пре 3 година
родитељ
комит
877f65b248

+ 0 - 11
src/Masuit.MyBlogs.Core/Common/CommonHelper.cs

@@ -403,17 +403,6 @@ namespace Masuit.MyBlogs.Core.Common
         {
             return ToTimeZone(time, zone).ToString(format);
         }
-
-        /// <summary>
-        /// 随机排序
-        /// </summary>
-        /// <typeparam name="T"></typeparam>
-        /// <param name="source"></param>
-        /// <returns></returns>
-        public static IOrderedQueryable<T> OrderByRandom<T>(this IQueryable<T> source)
-        {
-            return source.OrderBy(_ => DataContext.Random());
-        }
     }
 
     public class IPLocation

+ 0 - 2
src/Masuit.MyBlogs.Core/Controllers/BaseController.cs

@@ -22,8 +22,6 @@ using System.Net;
 using System.Text.RegularExpressions;
 using Masuit.MyBlogs.Core.Models.Enum;
 using SameSiteMode = Microsoft.AspNetCore.Http.SameSiteMode;
-using Newtonsoft.Json.Linq;
-using static Lucene.Net.Util.Fst.Util;
 
 namespace Masuit.MyBlogs.Core.Controllers
 {

+ 2 - 1
src/Masuit.MyBlogs.Core/Controllers/SearchController.cs

@@ -11,6 +11,7 @@ using Microsoft.AspNetCore.Mvc;
 using Microsoft.International.Converters.TraditionalChineseToSimplifiedConverter;
 using System.ComponentModel.DataAnnotations;
 using System.Linq.Expressions;
+using Masuit.Tools;
 
 namespace Masuit.MyBlogs.Core.Controllers
 {
@@ -40,7 +41,7 @@ namespace Masuit.MyBlogs.Core.Controllers
 
             ViewBag.PageSize = size;
             ViewBag.Keyword = wd;
-            if (!string.IsNullOrWhiteSpace(wd))
+            if (!wd.IsNullOrEmpty())
             {
                 var posts = postService.SearchPage(page, size, wd);
                 CheckPermission(posts.Results);

+ 0 - 16
src/Masuit.MyBlogs.Core/Infrastructure/DataContext.cs

@@ -73,17 +73,6 @@ namespace Masuit.MyBlogs.Core.Infrastructure
             modelBuilder.Entity<PostVisitRecordStats>().HasIndex(a => a.Date).HasSortOrder(SortOrder.Descending);
             modelBuilder.Entity<PostVisitRecordStats>().HasIndex(a => a.PostId).HasSortOrder(SortOrder.Ascending);
             modelBuilder.Entity<SearchDetails>().HasIndex(a => a.SearchTime).HasSortOrder(SortOrder.Descending);
-
-            if (Database.IsNpgsql() || Database.IsSqlite())
-            {
-                modelBuilder.HasDbFunction(typeof(DataContext).GetMethod(nameof(Random))).HasName("random");
-                modelBuilder.HasDbFunction(typeof(Guid).GetMethod(nameof(Guid.NewGuid))).HasName("random");
-            }
-            else
-            {
-                modelBuilder.HasDbFunction(typeof(DataContext).GetMethod(nameof(Random))).HasName("RAND");
-                modelBuilder.HasDbFunction(typeof(Guid).GetMethod(nameof(Guid.NewGuid))).HasName("RAND");
-            }
         }
 
         public override int SaveChanges()
@@ -162,8 +151,6 @@ namespace Masuit.MyBlogs.Core.Infrastructure
 
         public virtual DbSet<Seminar> Seminar { get; set; }
 
-        //public virtual DbSet<SeminarPost> SeminarPosts { get; set; }
-        //public virtual DbSet<SeminarPostHistoryVersion> SeminarPostHistoryVersions { get; set; }
         public virtual DbSet<InternalMessage> InternalMessage { get; set; }
 
         public virtual DbSet<FastShare> FastShare { get; set; }
@@ -177,8 +164,5 @@ namespace Masuit.MyBlogs.Core.Infrastructure
         public virtual DbSet<LinkLoopback> LinkLoopbacks { get; set; }
 
         public virtual DbSet<PostTag> PostTags { get; set; }
-
-        [DbFunction]
-        public static double Random() => throw new NotSupportedException();
     }
 }

+ 0 - 9
src/Masuit.MyBlogs.Core/Infrastructure/LoggerDbContext.cs

@@ -23,15 +23,6 @@ public class LoggerDbContext : DbContext
     {
         modelBuilder.Entity<RequestLogDetail>().HasKey(e => new { e.Id, e.Time });
         modelBuilder.Entity<PerformanceCounter>().HasKey(e => e.Time);
-
-        if (Database.IsNpgsql() || Database.IsSqlite())
-        {
-            modelBuilder.HasDbFunction(typeof(Guid).GetMethod(nameof(Guid.NewGuid))).HasName("random");
-        }
-        else
-        {
-            modelBuilder.HasDbFunction(typeof(Guid).GetMethod(nameof(Guid.NewGuid))).HasName("RAND");
-        }
     }
 }
 

+ 2 - 1
src/Masuit.MyBlogs.Core/Infrastructure/Services/AdvertisementService.cs

@@ -10,6 +10,7 @@ using Masuit.Tools;
 using Masuit.Tools.Linq;
 using System.Linq.Expressions;
 using System.Text.RegularExpressions;
+using Microsoft.EntityFrameworkCore;
 
 namespace Masuit.MyBlogs.Core.Infrastructure.Services
 {
@@ -73,7 +74,7 @@ namespace Masuit.MyBlogs.Core.Infrastructure.Services
                     where = where.And(a => Regex.IsMatch(a.Title + a.Description, regex));
                 }
 
-                var list = GetQuery(where).OrderBy(a => -Math.Log(DataContext.Random()) / ((double)a.Price / a.Types.Length * catCount / (string.IsNullOrEmpty(a.CategoryIds) ? catCount : (a.CategoryIds.Length + 1)))).Take(count).ToList();
+                var list = GetQuery(where).OrderBy(a => -Math.Log(EF.Functions.Random()) / ((double)a.Price / a.Types.Length * catCount / (string.IsNullOrEmpty(a.CategoryIds) ? catCount : (a.CategoryIds.Length + 1)))).Take(count).ToList();
                 if (list.Count == 0 && keywords is { Length: > 0 })
                 {
                     return GetsByWeightedPrice(count, type, ipinfo, cid);

+ 2 - 2
src/Masuit.MyBlogs.Core/Masuit.MyBlogs.Core.csproj

@@ -55,14 +55,14 @@
         <PackageReference Include="IP2Region" Version="1.2.0" />
         <PackageReference Include="Karambolo.AspNetCore.Bundling.NUglify" Version="3.5.1" />
         <PackageReference Include="Magick.NET-Q8-AnyCPU" Version="11.2.1" />
-        <PackageReference Include="Masuit.Tools.Excel" Version="1.2.1" />
+        <PackageReference Include="Masuit.Tools.Excel" Version="1.2.2" />
         <PackageReference Include="MaxMind.GeoIP2" Version="5.1.0" />
         <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.6" />
         <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.6" />
         <PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="6.0.6" />
         <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.6" />
         <PackageReference Include="Microsoft.Extensions.Http.Polly" Version="6.0.6" />
-        <PackageReference Include="Microsoft.Graph" Version="4.33.0" />
+        <PackageReference Include="Microsoft.Graph" Version="4.34.0" />
         <PackageReference Include="Microsoft.Graph.Auth" Version="1.0.0-preview.7" />
         <PackageReference Include="MiniProfiler.AspNetCore.Mvc" Version="4.2.22" />
         <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.5" />

+ 1 - 1
src/Masuit.MyBlogs.Core/Views/Dashboard/Counter.razor

@@ -166,7 +166,7 @@
     
     public Dictionary<string, dynamic> GetCounterPercent()
     {
-        using var counters = PerfCounter.CreateDataSource().Where(c => c.ServerIP==ip).OrderBy(c => Guid.NewGuid()).Take(5000).ToPooledList();
+        using var counters = PerfCounter.CreateDataSource().Where(c => c.ServerIP==ip).OrderByRandom().Take(5000).ToPooledList();
         var count = counters.Count();
         return new()
         {

+ 1 - 0
src/Masuit.MyBlogs.Core/Views/Shared/_ArticleListPartial.cshtml

@@ -4,6 +4,7 @@
 @using Masuit.MyBlogs.Core.Models.Enum
 @using Microsoft.AspNetCore.Mvc.TagHelpers
 @using Collections.Pooled
+@using Masuit.Tools.Core.AspNetCore
 @model Masuit.MyBlogs.Core.Models.ViewModel.HomePageViewModel
 @inject IPostService PostService
 

+ 1 - 0
src/Masuit.MyBlogs.Core/Views/Shared/_ArticleListPartial_Admin.cshtml

@@ -5,6 +5,7 @@
 @using Masuit.MyBlogs.Core.Models.Enum
 @using Microsoft.AspNetCore.Mvc.TagHelpers
 @using Collections.Pooled
+@using Masuit.Tools.Core.AspNetCore
 @model Masuit.MyBlogs.Core.Models.ViewModel.HomePageViewModel
 @inject IPostService PostService