From f540544a47f85fa41f5761a08bfc4d9fd18d3d46 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Fri, 27 Jun 2025 22:35:23 +0800 Subject: [PATCH] :sparkles: Activity debug include --- .../Activity/ActivityController.cs | 8 ++-- .../Activity/ActivityService.cs | 41 +++++++++++-------- DysonNetwork.Sphere/Chat/ChatController.cs | 6 +-- 3 files changed, 30 insertions(+), 25 deletions(-) diff --git a/DysonNetwork.Sphere/Activity/ActivityController.cs b/DysonNetwork.Sphere/Activity/ActivityController.cs index dcd4c34..3cd8d67 100644 --- a/DysonNetwork.Sphere/Activity/ActivityController.cs +++ b/DysonNetwork.Sphere/Activity/ActivityController.cs @@ -25,7 +25,8 @@ public class ActivityController( public async Task>> ListActivities( [FromQuery] string? cursor, [FromQuery] string? filter, - [FromQuery] int take = 20 + [FromQuery] int take = 20, + [FromQuery] string? debugInclude = null ) { Instant? cursorTimestamp = null; @@ -41,10 +42,11 @@ public class ActivityController( } } + var debugIncludeSet = debugInclude?.Split(',').ToHashSet() ?? new HashSet(); HttpContext.Items.TryGetValue("CurrentUser", out var currentUserValue); return currentUserValue is not Account.Account currentUser - ? Ok(await acts.GetActivitiesForAnyone(take, cursorTimestamp)) - : Ok(await acts.GetActivities(take, cursorTimestamp, currentUser, filter)); + ? Ok(await acts.GetActivitiesForAnyone(take, cursorTimestamp, debugIncludeSet)) + : Ok(await acts.GetActivities(take, cursorTimestamp, currentUser, filter, debugIncludeSet)); } } \ No newline at end of file diff --git a/DysonNetwork.Sphere/Activity/ActivityService.cs b/DysonNetwork.Sphere/Activity/ActivityService.cs index 5188ce0..df08abc 100644 --- a/DysonNetwork.Sphere/Activity/ActivityService.cs +++ b/DysonNetwork.Sphere/Activity/ActivityService.cs @@ -23,11 +23,12 @@ public class ActivityService( return (score + 1) / Math.Pow(hours + 2, 1.8); } - public async Task> GetActivitiesForAnyone(int take, Instant? cursor) + public async Task> GetActivitiesForAnyone(int take, Instant? cursor, HashSet? debugInclude = null) { var activities = new List(); + debugInclude ??= new HashSet(); - if (cursor == null && Random.Shared.NextDouble() < 0.2) + if (cursor == null && (debugInclude.Contains("realms") || Random.Shared.NextDouble() < 0.2)) { var realms = await ds.GetPublicRealmsAsync(null, null, 5, 0, true); if (realms.Count > 0) @@ -82,31 +83,37 @@ public class ActivityService( int take, Instant? cursor, Account.Account currentUser, - string? filter = null + string? filter = null, + HashSet? debugInclude = null ) { var activities = new List(); var userFriends = await rels.ListAccountFriends(currentUser); var userPublishers = await pub.GetUserPublishers(currentUser.Id); + debugInclude ??= new HashSet(); - if (cursor == null && Random.Shared.NextDouble() < 0.2) + if (string.IsNullOrEmpty(filter)) { - var realms = await ds.GetPublicRealmsAsync(null, null, 5, 0, true); - if (realms.Count > 0) + if (cursor == null && (debugInclude.Contains("realms") || Random.Shared.NextDouble() < 0.2)) { - activities.Add(new DiscoveryActivity( - realms.Select(x => new DiscoveryItem("realm", x)).ToList() - ).ToActivity()); + var realms = await ds.GetPublicRealmsAsync(null, null, 5, 0, true); + if (realms.Count > 0) + { + activities.Add(new DiscoveryActivity( + realms.Select(x => new DiscoveryItem("realm", x)).ToList() + ).ToActivity()); + } } - } - else if (cursor == null && Random.Shared.NextDouble() < 0.2) - { - var popularPublishers = await GetPopularPublishers(5); - if (popularPublishers.Count > 0) + + if (cursor == null && (debugInclude.Contains("publishers") || Random.Shared.NextDouble() < 0.2)) { - activities.Add(new DiscoveryActivity( - popularPublishers.Select(x => new DiscoveryItem("publisher", x)).ToList() - ).ToActivity()); + var popularPublishers = await GetPopularPublishers(5); + if (popularPublishers.Count > 0) + { + activities.Add(new DiscoveryActivity( + popularPublishers.Select(x => new DiscoveryItem("publisher", x)).ToList() + ).ToActivity()); + } } } diff --git a/DysonNetwork.Sphere/Chat/ChatController.cs b/DysonNetwork.Sphere/Chat/ChatController.cs index e1df461..2f78c81 100644 --- a/DysonNetwork.Sphere/Chat/ChatController.cs +++ b/DysonNetwork.Sphere/Chat/ChatController.cs @@ -1,14 +1,10 @@ using System.ComponentModel.DataAnnotations; -using System.Globalization; -using System.Text; using System.Text.RegularExpressions; using DysonNetwork.Sphere.Permission; using DysonNetwork.Sphere.Storage; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using NodaTime; -using SystemClock = NodaTime.SystemClock; namespace DysonNetwork.Sphere.Chat; @@ -310,4 +306,4 @@ public partial class ChatController(AppDatabase db, ChatService cs, ChatRoomServ var response = await cs.GetSyncDataAsync(roomId, request.LastSyncTimestamp); return Ok(response); } -} \ No newline at end of file +}