From 94a0ec71dac76fda7daf22a99c661ea3c0994e7a Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sat, 8 Nov 2025 13:21:29 +0800 Subject: [PATCH] :zap: Prevent from loading nested replied post --- DysonNetwork.Sphere/Post/PostController.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/DysonNetwork.Sphere/Post/PostController.cs b/DysonNetwork.Sphere/Post/PostController.cs index 71e7ccb..6a5ca61 100644 --- a/DysonNetwork.Sphere/Post/PostController.cs +++ b/DysonNetwork.Sphere/Post/PostController.cs @@ -219,6 +219,14 @@ public class PostController( var totalCount = await query.CountAsync(); var posts = await query.Skip(offset).Take(take).ToListAsync(); + foreach (var post in posts) + { + // Prevent load nested replied post + if (post.RepliedPost != null) + post.RepliedPost.RepliedPost = null; + } + + posts = await ps.LoadPostInfo(posts, currentUser, true); // Load realm data for posts that have realm @@ -475,9 +483,11 @@ public class PostController( var postsId = posts.Select(e => e.Id).ToList(); var reactionMaps = await ps.GetPostReactionMapBatch(postsId); foreach (var post in posts) + { post.ReactionsCount = reactionMaps.TryGetValue(post.Id, out var count) ? count : new Dictionary(); + } Response.Headers["X-Total"] = totalCount.ToString(); @@ -593,7 +603,7 @@ public class PostController( !await rs.IsMemberWithRole( realm.Id, accountId, - new List { RealmMemberRole.Normal } + [RealmMemberRole.Normal] ) ) return StatusCode(403, "You are not a member of this realm."); @@ -1164,4 +1174,4 @@ public class PostController( return NoContent(); } -} +} \ No newline at end of file