Compare commits

...

2 Commits

Author SHA1 Message Date
e477429a35 👔 Increase the chance of other type of activities show up
🗑️ Remove debug include in timeline
2025-12-06 21:12:08 +08:00
fe3a057185 👔 Discovery realms will show desc by member count 2025-12-06 21:10:08 +08:00
3 changed files with 13 additions and 30 deletions

View File

@@ -24,7 +24,7 @@ public class DiscoveryService(RemoteRealmService remoteRealmService)
// Since we don't have CreatedAt in the proto model, we'll just apply randomizer if requested
var orderedRealms = randomizer
? communityRealms.OrderBy(_ => Random.Shared.Next())
: communityRealms;
: communityRealms.OrderByDescending(q => q.Members.Count);
return orderedRealms.Skip(offset).Take(take).ToList();
}

View File

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

View File

@@ -32,14 +32,9 @@ public class TimelineService(
return performanceWeight / Math.Pow(normalizedTime + 1.0, 1.2);
}
public async Task<List<SnTimelineEvent>> ListEventsForAnyone(
int take,
Instant? cursor,
HashSet<string>? debugInclude = null
)
public async Task<List<SnTimelineEvent>> ListEventsForAnyone(int take, Instant? cursor)
{
var activities = new List<SnTimelineEvent>();
debugInclude ??= new HashSet<string>();
// Get and process posts
var publicRealms = await rs.GetPublicRealms();
@@ -60,7 +55,7 @@ public class TimelineService(
// Randomly insert a discovery activity before some posts
if (random.NextDouble() < 0.15)
{
var discovery = await MaybeGetDiscoveryActivity(debugInclude, cursor: cursor);
var discovery = await MaybeGetDiscoveryActivity(cursor: cursor);
if (discovery != null)
interleaved.Add(discovery);
}
@@ -80,12 +75,10 @@ public class TimelineService(
int take,
Instant? cursor,
Account currentUser,
string? filter = null,
HashSet<string>? debugInclude = null
string? filter = null
)
{
var activities = new List<SnTimelineEvent>();
debugInclude ??= new HashSet<string>();
// Get user's friends and publishers
var friendsResponse = await accounts.ListFriendsAsync(
@@ -126,7 +119,7 @@ public class TimelineService(
{
if (random.NextDouble() < 0.15)
{
var discovery = await MaybeGetDiscoveryActivity(debugInclude, cursor: cursor);
var discovery = await MaybeGetDiscoveryActivity(cursor: cursor);
if (discovery != null)
interleaved.Add(discovery);
}
@@ -142,21 +135,16 @@ public class TimelineService(
return activities;
}
private async Task<SnTimelineEvent?> MaybeGetDiscoveryActivity(
HashSet<string> debugInclude,
Instant? cursor
)
private async Task<SnTimelineEvent?> MaybeGetDiscoveryActivity(Instant? cursor)
{
if (cursor != null)
return null;
var options = new List<Func<Task<SnTimelineEvent?>>>();
if (debugInclude.Contains("realms") || Random.Shared.NextDouble() < 0.2)
if (Random.Shared.NextDouble() < 0.5)
options.Add(() => GetRealmDiscoveryActivity());
if (debugInclude.Contains("publishers") || Random.Shared.NextDouble() < 0.2)
if (Random.Shared.NextDouble() < 0.5)
options.Add(() => GetPublisherDiscoveryActivity());
if (debugInclude.Contains("articles") || Random.Shared.NextDouble() < 0.2)
if (Random.Shared.NextDouble() < 0.5)
options.Add(() => GetArticleDiscoveryActivity());
if (debugInclude.Contains("shuffledPosts") || Random.Shared.NextDouble() < 0.2)
if (Random.Shared.NextDouble() < 0.5)
options.Add(() => GetShuffledPostsActivity());
if (options.Count == 0)
return null;