浏览代码

修正bug

懒得勤快 4 年之前
父节点
当前提交
576b62be93

+ 1 - 1
src/Masuit.MyBlogs.Core/Controllers/PostController.cs

@@ -672,7 +672,7 @@ namespace Masuit.MyBlogs.Core.Controllers
             {
                 item.ModifyDate = item.ModifyDate.ToTimeZone(HttpContext.Session.Get<string>(SessionKey.TimeZone));
                 item.PostDate = item.PostDate.ToTimeZone(HttpContext.Session.Get<string>(SessionKey.TimeZone));
-                item.Online = cacheManager.GetOrAdd(nameof(PostOnline) + ":" + item.Id, new HashSet<string>()).Count;
+                item.Online = cacheManager.Get(nameof(PostOnline) + ":" + item.Id)?.Count ?? 0;
             }
 
             return Ok(list);

+ 5 - 5
src/Masuit.MyBlogs.Core/Infrastructure/Repository/LeaveMessageRepository.cs

@@ -1,11 +1,11 @@
-using System;
-using System.Linq;
-using System.Linq.Expressions;
-using System.Threading.Tasks;
-using Masuit.MyBlogs.Core.Infrastructure.Repository.Interface;
+using Masuit.MyBlogs.Core.Infrastructure.Repository.Interface;
 using Masuit.MyBlogs.Core.Models.Entity;
 using Masuit.Tools.Models;
 using Microsoft.EntityFrameworkCore;
+using System;
+using System.Linq;
+using System.Linq.Expressions;
+using System.Threading.Tasks;
 
 namespace Masuit.MyBlogs.Core.Infrastructure.Repository
 {

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

@@ -65,7 +65,7 @@
         <PackageReference Include="TimeZoneConverter" Version="3.4.0" />
         <PackageReference Include="WilderMinds.RssSyndication" Version="1.7.0" />
         <PackageReference Include="WinInsider.System.Net.Http.Formatting" Version="1.0.14" />
-        <PackageReference Include="Z.EntityFramework.Plus.EFCore" Version="5.1.28" />
+        <PackageReference Include="Z.EntityFramework.Plus.EFCore" Version="5.1.29" />
     </ItemGroup>
     <ItemGroup>
         <Content Update="appsettings.json">

+ 1 - 2
src/Masuit.MyBlogs.Core/Views/Post/PostOnline.razor

@@ -1,6 +1,5 @@
 @using CacheManager.Core
 @using System.Threading
-@using Masuit.MyBlogs.Core.Common
 @implements IAsyncDisposable
 @inject ICacheManager<HashSet<string>> CacheManager
 
@@ -27,7 +26,7 @@
         CacheManager.Expire(key, ExpirationMode.Sliding, TimeSpan.FromMinutes(5));
         _timer = new Timer(_ =>
         {
-            online = CacheManager.Get(key).Count;
+            online = CacheManager.Get(key)?.Count ?? 0;
             InvokeAsync(StateHasChanged);
         }, null, 0, 1000);
     }

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

@@ -6,7 +6,7 @@
 @inject ICacheManager<HashSet<string>> CacheManager
 @{
     string[] colors = { "success", "info", "primary", "warning", "danger", "default", "primary" };
-    var online = CacheManager.GetOrAdd(nameof(PostOnline) + ":" + Model.Id, new HashSet<string>()).Count;
+    var online = CacheManager.Get(nameof(PostOnline) + ":" + Model.Id)?.Count ?? 0;
 }
 
 <div class="ibox wow fadeIn">

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

@@ -7,7 +7,7 @@
 @model Masuit.MyBlogs.Core.Models.DTO.PostDto
 @{
     string[] colors = { "success", "info", "primary", "warning", "danger", "default", "primary" };
-    var online = CacheManager.GetOrAdd(nameof(PostOnline) + ":" + Model.Id, new HashSet<string>()).Count;
+    var online = CacheManager.Get(nameof(PostOnline) + ":" + Model.Id)?.Count ?? 0;
 }
 
 <div class="ibox wow fadeIn">