Activity debug include

This commit is contained in:
LittleSheep 2025-06-27 22:35:23 +08:00
parent 9f8eec792b
commit f540544a47
3 changed files with 30 additions and 25 deletions

View File

@ -25,7 +25,8 @@ public class ActivityController(
public async Task<ActionResult<List<Activity>>> ListActivities( public async Task<ActionResult<List<Activity>>> ListActivities(
[FromQuery] string? cursor, [FromQuery] string? cursor,
[FromQuery] string? filter, [FromQuery] string? filter,
[FromQuery] int take = 20 [FromQuery] int take = 20,
[FromQuery] string? debugInclude = null
) )
{ {
Instant? cursorTimestamp = null; Instant? cursorTimestamp = null;
@ -41,10 +42,11 @@ public class ActivityController(
} }
} }
var debugIncludeSet = debugInclude?.Split(',').ToHashSet() ?? new HashSet<string>();
HttpContext.Items.TryGetValue("CurrentUser", out var currentUserValue); HttpContext.Items.TryGetValue("CurrentUser", out var currentUserValue);
return currentUserValue is not Account.Account currentUser return currentUserValue is not Account.Account currentUser
? Ok(await acts.GetActivitiesForAnyone(take, cursorTimestamp)) ? Ok(await acts.GetActivitiesForAnyone(take, cursorTimestamp, debugIncludeSet))
: Ok(await acts.GetActivities(take, cursorTimestamp, currentUser, filter)); : Ok(await acts.GetActivities(take, cursorTimestamp, currentUser, filter, debugIncludeSet));
} }
} }

View File

@ -23,11 +23,12 @@ public class ActivityService(
return (score + 1) / Math.Pow(hours + 2, 1.8); return (score + 1) / Math.Pow(hours + 2, 1.8);
} }
public async Task<List<Activity>> GetActivitiesForAnyone(int take, Instant? cursor) public async Task<List<Activity>> GetActivitiesForAnyone(int take, Instant? cursor, HashSet<string>? debugInclude = null)
{ {
var activities = new List<Activity>(); var activities = new List<Activity>();
debugInclude ??= new HashSet<string>();
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); var realms = await ds.GetPublicRealmsAsync(null, null, 5, 0, true);
if (realms.Count > 0) if (realms.Count > 0)
@ -82,14 +83,18 @@ public class ActivityService(
int take, int take,
Instant? cursor, Instant? cursor,
Account.Account currentUser, Account.Account currentUser,
string? filter = null string? filter = null,
HashSet<string>? debugInclude = null
) )
{ {
var activities = new List<Activity>(); var activities = new List<Activity>();
var userFriends = await rels.ListAccountFriends(currentUser); var userFriends = await rels.ListAccountFriends(currentUser);
var userPublishers = await pub.GetUserPublishers(currentUser.Id); var userPublishers = await pub.GetUserPublishers(currentUser.Id);
debugInclude ??= new HashSet<string>();
if (cursor == null && Random.Shared.NextDouble() < 0.2) if (string.IsNullOrEmpty(filter))
{
if (cursor == null && (debugInclude.Contains("realms") || Random.Shared.NextDouble() < 0.2))
{ {
var realms = await ds.GetPublicRealmsAsync(null, null, 5, 0, true); var realms = await ds.GetPublicRealmsAsync(null, null, 5, 0, true);
if (realms.Count > 0) if (realms.Count > 0)
@ -99,7 +104,8 @@ public class ActivityService(
).ToActivity()); ).ToActivity());
} }
} }
else if (cursor == null && Random.Shared.NextDouble() < 0.2)
if (cursor == null && (debugInclude.Contains("publishers") || Random.Shared.NextDouble() < 0.2))
{ {
var popularPublishers = await GetPopularPublishers(5); var popularPublishers = await GetPopularPublishers(5);
if (popularPublishers.Count > 0) if (popularPublishers.Count > 0)
@ -109,6 +115,7 @@ public class ActivityService(
).ToActivity()); ).ToActivity());
} }
} }
}
// Get publishers based on filter // Get publishers based on filter
var filteredPublishers = filter switch var filteredPublishers = filter switch

View File

@ -1,14 +1,10 @@
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using DysonNetwork.Sphere.Permission; using DysonNetwork.Sphere.Permission;
using DysonNetwork.Sphere.Storage; using DysonNetwork.Sphere.Storage;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using NodaTime;
using SystemClock = NodaTime.SystemClock;
namespace DysonNetwork.Sphere.Chat; namespace DysonNetwork.Sphere.Chat;