Web articles

This commit is contained in:
2025-07-01 00:44:48 +08:00
parent ccb8a4e3f4
commit 05bf2cd055
3 changed files with 131 additions and 1 deletions

View File

@ -1,4 +1,5 @@
using DysonNetwork.Sphere.Account;
using DysonNetwork.Sphere.Connection.WebReader;
using DysonNetwork.Sphere.Discovery;
using DysonNetwork.Sphere.Post;
using DysonNetwork.Sphere.Publisher;
@ -39,6 +40,31 @@ public class ActivityService(
}
}
if (debugInclude.Contains("articles") || Random.Shared.NextDouble() < 0.2)
{
var recentArticlesQuery = db.WebArticles
.Take(20); // Get a larger pool for randomization
// Apply random ordering 50% of the time
if (Random.Shared.NextDouble() < 0.5)
{
recentArticlesQuery = recentArticlesQuery.OrderBy(_ => EF.Functions.Random());
}
else
{
recentArticlesQuery = recentArticlesQuery.OrderByDescending(a => a.PublishedAt);
}
var recentArticles = await recentArticlesQuery.Take(5).ToListAsync();
if (recentArticles.Count > 0)
{
activities.Add(new DiscoveryActivity(
recentArticles.Select(x => new DiscoveryItem("article", x)).ToList()
).ToActivity());
}
}
// Fetch a larger batch of recent posts to rank
var postsQuery = db.Posts
.Include(e => e.RepliedPost)
@ -115,6 +141,27 @@ public class ActivityService(
).ToActivity());
}
}
if (debugInclude.Contains("articles") || Random.Shared.NextDouble() < 0.2)
{
var recentArticlesQuery = db.WebArticles
.Take(20); // Get a larger pool for randomization
// Apply random ordering 50% of the time
if (Random.Shared.NextDouble() < 0.5)
recentArticlesQuery = recentArticlesQuery.OrderBy(_ => EF.Functions.Random());
else
recentArticlesQuery = recentArticlesQuery.OrderByDescending(a => a.PublishedAt);
var recentArticles = await recentArticlesQuery.Take(5).ToListAsync();
if (recentArticles.Count > 0)
{
activities.Add(new DiscoveryActivity(
recentArticles.Select(x => new DiscoveryItem("article", x)).ToList()
).ToActivity());
}
}
}
// Get publishers based on filter