[backend/masto-client] Move offset pagination into QueryableExtensions

This commit is contained in:
Laura Hausmann 2024-05-16 00:38:16 +02:00
parent 961bda0164
commit 498ac154a7
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
2 changed files with 3 additions and 6 deletions

View file

@ -133,7 +133,6 @@ public class SearchController(
.Where(p => p.DisplayNameOrUsernameOrFqnContainsCaseInsensitive(search.Query!,
config.Value.AccountDomain))
.Where(p => !search.Following || p.IsFollowedBy(user))
.Skip(pagination.Offset ?? 0)
.Paginate(pagination, ControllerContext) //TODO: this will mess up our sorting
.OrderByDescending(p => p.NotesCount)
.RenderAllForMastodonAsync(userRenderer);
@ -185,7 +184,6 @@ public class SearchController(
.FilterByUser(search.UserId)
.EnsureVisibleFor(user)
.FilterHidden(user, db)
.Skip(pagination.Offset ?? 0)
.Paginate(pagination, ControllerContext)
.PrecomputeVisibilities(user)
.RenderAllForMastodonAsync(noteRenderer, user);
@ -200,7 +198,6 @@ public class SearchController(
{
return await db.Hashtags
.Where(p => EF.Functions.ILike(p.Name, "%" + EfHelpers.EscapeLikeQuery(search.Query!) + "%"))
.Skip(pagination.Offset ?? 0)
.Paginate(pagination, ControllerContext)
.OrderByDescending(p => p.Id)
.Select(p => new TagEntity

View file

@ -47,7 +47,7 @@ public static class QueryableExtensions
_ => query.OrderByDescending(p => p.Id)
};
return query.Take(Math.Min(pq.Limit ?? defaultLimit, maxLimit));
return query.Skip(pq.Offset ?? 0).Take(Math.Min(pq.Limit ?? defaultLimit, maxLimit));
}
public static IQueryable<T> Paginate<T>(
@ -83,7 +83,7 @@ public static class QueryableExtensions
_ => query.OrderByDescending(predicate)
};
return query.Take(Math.Min(pq.Limit ?? defaultLimit, maxLimit));
return query.Skip(pq.Offset ?? 0).Take(Math.Min(pq.Limit ?? defaultLimit, maxLimit));
}
public static IQueryable<T> Paginate<T>(
@ -137,7 +137,7 @@ public static class QueryableExtensions
_ => query.OrderByDescending(predicate)
};
return query.Take(Math.Min(pq.Limit ?? defaultLimit, maxLimit));
return query.Skip(pq.Offset ?? 0).Take(Math.Min(pq.Limit ?? defaultLimit, maxLimit));
}
public static IQueryable<T> Paginate<T>(