Переглянути джерело

修复标签统计逻辑,仅统计已发布文章

修改了 `PostController` 中 `PostTagService.AddOrUpdate` 的调用逻辑,增加了对文章状态的过滤条件,仅统计状态为 `Published` 的文章数量。
调整影响了新增文章、修改文章和发表文章的相关逻辑,确保标签统计数据准确无误。
懒得勤快 3 днів тому
батько
коміт
46d4f0f7de

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

@@ -308,7 +308,7 @@ public sealed class PostController : BaseController
         PostTagService.AddOrUpdate(t => t.Name, p.Label.AsNotNull().Split(',', StringSplitOptions.RemoveEmptyEntries).Select(s => new PostTag()
         {
             Name = s,
-            Count = PostService.Count(t => t.Label.Contains(s))
+            Count = PostService.Count(t => t.Label.Contains(s) && t.Status == Status.Published)
         }));
         p = PostService.AddEntitySaved(p);
         if (p == null)
@@ -800,7 +800,7 @@ public sealed class PostController : BaseController
         PostTagService.AddOrUpdate(t => t.Name, post.Label.AsNotNull().Split(',', StringSplitOptions.RemoveEmptyEntries).Select(s => new PostTag()
         {
             Name = s,
-            Count = PostService.Count(t => t.Label.Contains(s))
+            Count = PostService.Count(t => t.Label.Contains(s) && t.Status == Status.Published)
         }));
         bool b = await SearchEngine.SaveChangesAsync() > 0;
         if (!b)
@@ -862,7 +862,7 @@ public sealed class PostController : BaseController
         PostTagService.AddOrUpdate(t => t.Name, post.Label.AsNotNull().Split(',', StringSplitOptions.RemoveEmptyEntries).Select(s => new PostTag()
         {
             Name = s,
-            Count = PostService.Count(t => t.Label.Contains(s))
+            Count = PostService.Count(t => t.Label.Contains(s) && t.Status == Status.Published)
         }));
         bool b = await SearchEngine.SaveChangesAsync() > 0;
         if (!b)