From 7ad9deaf70dccdcba720eb40b8e51909b16783a0 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Fri, 22 Aug 2025 16:50:06 +0800 Subject: [PATCH] :art: Adjust post shuffle query --- DysonNetwork.Sphere/Post/PostController.cs | 23 +++++++++++----------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/DysonNetwork.Sphere/Post/PostController.cs b/DysonNetwork.Sphere/Post/PostController.cs index c6d2b1f..c6ea9eb 100644 --- a/DysonNetwork.Sphere/Post/PostController.cs +++ b/DysonNetwork.Sphere/Post/PostController.cs @@ -60,7 +60,7 @@ public class PostController( if (currentUser != null) { var friendsResponse = await accounts.ListFriendsAsync(new ListRelationshipSimpleRequest - { AccountId = currentUser.Id }); + { AccountId = currentUser.Id }); userFriends = friendsResponse.AccountsId.Select(Guid.Parse).ToList(); } @@ -106,10 +106,9 @@ public class PostController( var totalCount = await query .CountAsync(); - if (shuffle) - query = query.OrderBy(e => EF.Functions.Random()); - else - query = query.OrderByDescending(e => e.PublishedAt ?? e.CreatedAt); + query = shuffle + ? query.OrderBy(e => EF.Functions.Random()) + : query.OrderByDescending(e => e.PublishedAt ?? e.CreatedAt); var posts = await query .Include(e => e.RepliedPost) @@ -134,7 +133,7 @@ public class PostController( if (currentUser != null) { var friendsResponse = await accounts.ListFriendsAsync(new ListRelationshipSimpleRequest - { AccountId = currentUser.Id }); + { AccountId = currentUser.Id }); userFriends = friendsResponse.AccountsId.Select(Guid.Parse).ToList(); } @@ -168,7 +167,7 @@ public class PostController( if (currentUser != null) { var friendsResponse = await accounts.ListFriendsAsync(new ListRelationshipSimpleRequest - { AccountId = currentUser.Id }); + { AccountId = currentUser.Id }); userFriends = friendsResponse.AccountsId.Select(Guid.Parse).ToList(); } @@ -211,7 +210,7 @@ public class PostController( if (currentUser != null) { var friendsResponse = await accounts.ListFriendsAsync(new ListRelationshipSimpleRequest - { AccountId = currentUser.Id }); + { AccountId = currentUser.Id }); userFriends = friendsResponse.AccountsId.Select(Guid.Parse).ToList(); } @@ -279,7 +278,7 @@ public class PostController( if (currentUser != null) { var friendsResponse = await accounts.ListFriendsAsync(new ListRelationshipSimpleRequest - { AccountId = currentUser.Id }); + { AccountId = currentUser.Id }); userFriends = friendsResponse.AccountsId.Select(Guid.Parse).ToList(); } @@ -315,7 +314,7 @@ public class PostController( if (currentUser != null) { var friendsResponse = await accounts.ListFriendsAsync(new ListRelationshipSimpleRequest - { AccountId = currentUser.Id }); + { AccountId = currentUser.Id }); userFriends = friendsResponse.AccountsId.Select(Guid.Parse).ToList(); } @@ -502,7 +501,7 @@ public class PostController( var friendsResponse = await accounts.ListFriendsAsync(new ListRelationshipSimpleRequest - { AccountId = currentUser.Id.ToString() }); + { AccountId = currentUser.Id.ToString() }); var userFriends = friendsResponse.AccountsId.Select(Guid.Parse).ToList(); var userPublishers = await pub.GetUserPublishers(Guid.Parse(currentUser.Id)); @@ -697,4 +696,4 @@ public class PostController( return NoContent(); } -} +} \ No newline at end of file