From 7f110313e9b66edd65d26d1af52e1ef2360396ef Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Wed, 3 Sep 2025 23:32:44 +0800 Subject: [PATCH] :bug: Fix inconsistent post data in activity --- DysonNetwork.Sphere/Activity/ActivityService.cs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/DysonNetwork.Sphere/Activity/ActivityService.cs b/DysonNetwork.Sphere/Activity/ActivityService.cs index bfc41ac..a74e0f3 100644 --- a/DysonNetwork.Sphere/Activity/ActivityService.cs +++ b/DysonNetwork.Sphere/Activity/ActivityService.cs @@ -61,8 +61,10 @@ public class ActivityService( if (discovery != null) interleaved.Add(discovery); } + interleaved.Add(post.ToActivity()); } + activities.AddRange(interleaved); if (activities.Count == 0) @@ -127,8 +129,10 @@ public class ActivityService( if (discovery != null) interleaved.Add(discovery); } + interleaved.Add(post.ToActivity()); } + activities.AddRange(interleaved); if (activities.Count == 0) @@ -210,19 +214,19 @@ public class ActivityService( private async Task GetShuffledPostsActivity(int count = 5) { - var posts = await db.Posts + var postsQuery = db.Posts .Include(p => p.Categories) .Include(p => p.Tags) .Include(p => p.Realm) .Where(p => p.RepliedPostId == null) .OrderBy(_ => EF.Functions.Random()) - .Take(count) - .ToListAsync(); + .Take(count); - if (posts.Count == 0) - return null; + var posts = await GetAndProcessPosts(postsQuery, trackViews: false); - return new DiscoveryActivity(posts.Select(x => new DiscoveryItem("post", x)).ToList()).ToActivity(); + return posts.Count == 0 + ? null + : new DiscoveryActivity(posts.Select(x => new DiscoveryItem("post", x)).ToList()).ToActivity(); } private async Task GetArticleDiscoveryActivity(int count = 5, int feedSampleSize = 10)