diff --git a/Iceshrimp.Backend/Controllers/Mastodon/TimelineController.cs b/Iceshrimp.Backend/Controllers/Mastodon/TimelineController.cs index 3c190c6b..ec935625 100644 --- a/Iceshrimp.Backend/Controllers/Mastodon/TimelineController.cs +++ b/Iceshrimp.Backend/Controllers/Mastodon/TimelineController.cs @@ -31,11 +31,10 @@ public class TimelineController(DatabaseContext db, NoteRenderer noteRenderer, C public async Task GetHomeTimeline(MastodonPaginationQuery query) { var user = HttpContext.GetUserOrFail(); - var heuristic = await QueryableTimelineExtensions.GetHeuristic(user, db, cache); var res = await db.Notes .IncludeCommonProperties() - .FilterByFollowingAndOwn(user, db, heuristic) + .FilterByFollowingAndOwn(user, db) .EnsureVisibleFor(user) .FilterHidden(user, db, filterHiddenListMembers: true) .Paginate(query, ControllerContext) diff --git a/Iceshrimp.Backend/Controllers/TimelineController.cs b/Iceshrimp.Backend/Controllers/TimelineController.cs index 3eebfa5b..aedeed35 100644 --- a/Iceshrimp.Backend/Controllers/TimelineController.cs +++ b/Iceshrimp.Backend/Controllers/TimelineController.cs @@ -29,9 +29,8 @@ public class TimelineController(DatabaseContext db, CacheService cache, NoteRend public async Task GetHomeTimeline(PaginationQuery pq) { var user = HttpContext.GetUserOrFail(); - var heuristic = await QueryableTimelineExtensions.GetHeuristic(user, db, cache); var notes = await db.Notes.IncludeCommonProperties() - .FilterByFollowingAndOwn(user, db, heuristic) + .FilterByFollowingAndOwn(user, db) .EnsureVisibleFor(user) .FilterHidden(user, db, filterHiddenListMembers: true) .Paginate(pq, ControllerContext) diff --git a/Iceshrimp.Backend/Core/Extensions/QueryableTimelineExtensions.cs b/Iceshrimp.Backend/Core/Extensions/QueryableTimelineExtensions.cs index f7aa77e8..907ff17a 100644 --- a/Iceshrimp.Backend/Core/Extensions/QueryableTimelineExtensions.cs +++ b/Iceshrimp.Backend/Core/Extensions/QueryableTimelineExtensions.cs @@ -12,12 +12,14 @@ public static class QueryableTimelineExtensions private const int Cutoff = 250; public static IQueryable FilterByFollowingAndOwn( - this IQueryable query, User user, DatabaseContext db, int heuristic + this IQueryable query, User user, DatabaseContext db ) { - return heuristic < Cutoff - ? query.FollowingAndOwnLowFreq(user, db) - : query.Where(note => note.User == user || note.User.IsFollowedBy(user)); + return query.Where(note => db.Followings + .Where(p => p.Follower == user) + .Select(p => p.FolloweeId) + .Concat(new[] { user.Id }) + .Contains(note.UserId)); } private static IQueryable FollowingAndOwnLowFreq(this IQueryable query, User user, DatabaseContext db) @@ -26,27 +28,4 @@ public static class QueryableTimelineExtensions .Select(p => p.FolloweeId) .Concat(new[] { user.Id }) .Contains(note.UserId)); - - public static async Task GetHeuristic(User user, DatabaseContext db, CacheService cache) - { - return await cache.FetchValueAsync($"following-query-heuristic:{user.Id}", - TimeSpan.FromHours(24), FetchHeuristic); - - [SuppressMessage("ReSharper", "EntityFramework.UnsupportedServerSideFunctionCall")] - async Task FetchHeuristic() - { - var latestNote = await db.Notes.OrderByDescending(p => p.Id) - .Select(p => new { p.CreatedAt }) - .FirstOrDefaultAsync() ?? - new { CreatedAt = DateTime.UtcNow }; - - //TODO: maybe we should express this as a ratio between matching and non-matching posts - return await db.Notes - .Where(p => p.CreatedAt > latestNote.CreatedAt - TimeSpan.FromDays(7)) - .FollowingAndOwnLowFreq(user, db) - //.Select(p => new { }) - .Take(Cutoff + 1) - .CountAsync(); - } - } } \ No newline at end of file