Compare commits
2 Commits
ad3c104c5c
...
e477429a35
| Author | SHA1 | Date | |
|---|---|---|---|
|
e477429a35
|
|||
|
fe3a057185
|
@@ -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
|
// Since we don't have CreatedAt in the proto model, we'll just apply randomizer if requested
|
||||||
var orderedRealms = randomizer
|
var orderedRealms = randomizer
|
||||||
? communityRealms.OrderBy(_ => Random.Shared.Next())
|
? communityRealms.OrderBy(_ => Random.Shared.Next())
|
||||||
: communityRealms;
|
: communityRealms.OrderByDescending(q => q.Members.Count);
|
||||||
|
|
||||||
return orderedRealms.Skip(offset).Take(take).ToList();
|
return orderedRealms.Skip(offset).Take(take).ToList();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,8 +25,7 @@ public class ActivityController(TimelineService acts) : ControllerBase
|
|||||||
public async Task<ActionResult<List<SnTimelineEvent>>> ListEvents(
|
public async Task<ActionResult<List<SnTimelineEvent>>> ListEvents(
|
||||||
[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;
|
||||||
@@ -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);
|
HttpContext.Items.TryGetValue("CurrentUser", out var currentUserValue);
|
||||||
return currentUserValue is not Account currentUser
|
return currentUserValue is not Account currentUser
|
||||||
? Ok(await acts.ListEventsForAnyone(take, cursorTimestamp, debugIncludeSet))
|
? Ok(await acts.ListEventsForAnyone(take, cursorTimestamp))
|
||||||
: Ok(
|
: Ok(await acts.ListEvents(take, cursorTimestamp, currentUser, filter));
|
||||||
await acts.ListEvents(take, cursorTimestamp, currentUser, filter, debugIncludeSet)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,14 +32,9 @@ public class TimelineService(
|
|||||||
return performanceWeight / Math.Pow(normalizedTime + 1.0, 1.2);
|
return performanceWeight / Math.Pow(normalizedTime + 1.0, 1.2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<List<SnTimelineEvent>> ListEventsForAnyone(
|
public async Task<List<SnTimelineEvent>> ListEventsForAnyone(int take, Instant? cursor)
|
||||||
int take,
|
|
||||||
Instant? cursor,
|
|
||||||
HashSet<string>? debugInclude = null
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
var activities = new List<SnTimelineEvent>();
|
var activities = new List<SnTimelineEvent>();
|
||||||
debugInclude ??= new HashSet<string>();
|
|
||||||
|
|
||||||
// Get and process posts
|
// Get and process posts
|
||||||
var publicRealms = await rs.GetPublicRealms();
|
var publicRealms = await rs.GetPublicRealms();
|
||||||
@@ -60,7 +55,7 @@ public class TimelineService(
|
|||||||
// Randomly insert a discovery activity before some posts
|
// Randomly insert a discovery activity before some posts
|
||||||
if (random.NextDouble() < 0.15)
|
if (random.NextDouble() < 0.15)
|
||||||
{
|
{
|
||||||
var discovery = await MaybeGetDiscoveryActivity(debugInclude, cursor: cursor);
|
var discovery = await MaybeGetDiscoveryActivity(cursor: cursor);
|
||||||
if (discovery != null)
|
if (discovery != null)
|
||||||
interleaved.Add(discovery);
|
interleaved.Add(discovery);
|
||||||
}
|
}
|
||||||
@@ -80,12 +75,10 @@ public class TimelineService(
|
|||||||
int take,
|
int take,
|
||||||
Instant? cursor,
|
Instant? cursor,
|
||||||
Account currentUser,
|
Account currentUser,
|
||||||
string? filter = null,
|
string? filter = null
|
||||||
HashSet<string>? debugInclude = null
|
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
var activities = new List<SnTimelineEvent>();
|
var activities = new List<SnTimelineEvent>();
|
||||||
debugInclude ??= new HashSet<string>();
|
|
||||||
|
|
||||||
// Get user's friends and publishers
|
// Get user's friends and publishers
|
||||||
var friendsResponse = await accounts.ListFriendsAsync(
|
var friendsResponse = await accounts.ListFriendsAsync(
|
||||||
@@ -126,7 +119,7 @@ public class TimelineService(
|
|||||||
{
|
{
|
||||||
if (random.NextDouble() < 0.15)
|
if (random.NextDouble() < 0.15)
|
||||||
{
|
{
|
||||||
var discovery = await MaybeGetDiscoveryActivity(debugInclude, cursor: cursor);
|
var discovery = await MaybeGetDiscoveryActivity(cursor: cursor);
|
||||||
if (discovery != null)
|
if (discovery != null)
|
||||||
interleaved.Add(discovery);
|
interleaved.Add(discovery);
|
||||||
}
|
}
|
||||||
@@ -142,21 +135,16 @@ public class TimelineService(
|
|||||||
return activities;
|
return activities;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<SnTimelineEvent?> MaybeGetDiscoveryActivity(
|
private async Task<SnTimelineEvent?> MaybeGetDiscoveryActivity(Instant? cursor)
|
||||||
HashSet<string> debugInclude,
|
|
||||||
Instant? cursor
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
if (cursor != null)
|
|
||||||
return null;
|
|
||||||
var options = new List<Func<Task<SnTimelineEvent?>>>();
|
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());
|
options.Add(() => GetRealmDiscoveryActivity());
|
||||||
if (debugInclude.Contains("publishers") || Random.Shared.NextDouble() < 0.2)
|
if (Random.Shared.NextDouble() < 0.5)
|
||||||
options.Add(() => GetPublisherDiscoveryActivity());
|
options.Add(() => GetPublisherDiscoveryActivity());
|
||||||
if (debugInclude.Contains("articles") || Random.Shared.NextDouble() < 0.2)
|
if (Random.Shared.NextDouble() < 0.5)
|
||||||
options.Add(() => GetArticleDiscoveryActivity());
|
options.Add(() => GetArticleDiscoveryActivity());
|
||||||
if (debugInclude.Contains("shuffledPosts") || Random.Shared.NextDouble() < 0.2)
|
if (Random.Shared.NextDouble() < 0.5)
|
||||||
options.Add(() => GetShuffledPostsActivity());
|
options.Add(() => GetShuffledPostsActivity());
|
||||||
if (options.Count == 0)
|
if (options.Count == 0)
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
Reference in New Issue
Block a user