🐛 Fix get the posts repeatly
This commit is contained in:
@ -10,7 +10,7 @@ public class ActivityService(AppDatabase db, RelationshipService rels, PostServi
|
||||
public async Task<List<Activity>> GetActivitiesForAnyone(int take, Instant? cursor)
|
||||
{
|
||||
var activities = new List<Activity>();
|
||||
|
||||
|
||||
// Crunching up data
|
||||
var posts = await db.Posts
|
||||
.Include(e => e.RepliedPost)
|
||||
@ -18,7 +18,7 @@ public class ActivityService(AppDatabase db, RelationshipService rels, PostServi
|
||||
.Include(e => e.Categories)
|
||||
.Include(e => e.Tags)
|
||||
.Where(e => e.RepliedPostId == null)
|
||||
.Where(p => cursor == null || cursor > p.CreatedAt)
|
||||
.Where(p => cursor == null || p.PublishedAt < cursor)
|
||||
.OrderByDescending(p => p.PublishedAt)
|
||||
.FilterWithVisibility(null, [], isListing: true)
|
||||
.Take(take)
|
||||
@ -31,22 +31,22 @@ public class ActivityService(AppDatabase db, RelationshipService rels, PostServi
|
||||
foreach (var post in posts)
|
||||
post.ReactionsCount =
|
||||
reactionMaps.TryGetValue(post.Id, out var count) ? count : new Dictionary<string, int>();
|
||||
|
||||
|
||||
// Formatting data
|
||||
foreach (var post in posts)
|
||||
activities.Add(post.ToActivity());
|
||||
|
||||
|
||||
if (activities.Count == 0)
|
||||
activities.Add(Activity.Empty());
|
||||
|
||||
return activities;
|
||||
}
|
||||
|
||||
|
||||
public async Task<List<Activity>> GetActivities(int take, Instant? cursor, Account.Account currentUser)
|
||||
{
|
||||
var activities = new List<Activity>();
|
||||
var userFriends = await rels.ListAccountFriends(currentUser);
|
||||
|
||||
|
||||
// Crunching data
|
||||
var posts = await db.Posts
|
||||
.Include(e => e.RepliedPost)
|
||||
@ -54,7 +54,7 @@ public class ActivityService(AppDatabase db, RelationshipService rels, PostServi
|
||||
.Include(e => e.Categories)
|
||||
.Include(e => e.Tags)
|
||||
.Where(e => e.RepliedPostId == null)
|
||||
.Where(p => cursor == null || p.CreatedAt > cursor)
|
||||
.Where(p => cursor == null || p.PublishedAt < cursor)
|
||||
.OrderByDescending(p => p.PublishedAt)
|
||||
.FilterWithVisibility(currentUser, userFriends, isListing: true)
|
||||
.Take(take)
|
||||
@ -67,11 +67,11 @@ public class ActivityService(AppDatabase db, RelationshipService rels, PostServi
|
||||
foreach (var post in posts)
|
||||
post.ReactionsCount =
|
||||
reactionMaps.TryGetValue(post.Id, out var count) ? count : new Dictionary<string, int>();
|
||||
|
||||
|
||||
// Formatting data
|
||||
foreach (var post in posts)
|
||||
activities.Add(post.ToActivity());
|
||||
|
||||
|
||||
if (activities.Count == 0)
|
||||
activities.Add(Activity.Empty());
|
||||
|
||||
|
Reference in New Issue
Block a user