chore: unify pagination options in trait

This commit is contained in:
əlemi 2024-12-26 15:40:12 +01:00
parent 3bebd8bccf
commit 69071c1320
Signed by: alemi
GPG key ID: A4895B84D311642C
6 changed files with 13 additions and 10 deletions

View file

@ -59,8 +59,7 @@ pub async fn page<const OUTGOING: bool>(
use upub::model::relation::Column::{Follower, Following, FollowerInstance, FollowingInstance};
let follow___ = if OUTGOING { "following" } else { "followers" };
let limit = page.batch.unwrap_or(100).min(500);
let offset = page.offset.unwrap_or(0);
let (limit, offset) = page.pagination();
let (user, config) = model::actor::Entity::find_by_ap_id(&ctx.uid(&id))
.find_also_related(model::config::Entity)

View file

@ -39,8 +39,7 @@ pub async fn page(
return Err(crate::ApiError::forbidden());
}
let limit = page.batch.unwrap_or(20).min(50);
let offset = page.offset.unwrap_or(0);
let (limit, offset) = page.pagination();
let activities = upub::Query::notifications(*internal, true)
.limit(limit)

View file

@ -94,6 +94,14 @@ pub struct Pagination {
pub replies: Option<bool>,
}
impl Pagination {
pub fn pagination(&self) -> (u64, u64) {
let limit = self.batch.unwrap_or(20).min(50);
let offset = self.offset.unwrap_or(0);
(limit, offset)
}
}
#[derive(Debug, serde::Deserialize)]
// TODO i don't really like how pleroma/mastodon do it actually, maybe change this?
pub struct PaginatedSearch {

View file

@ -27,8 +27,7 @@ pub async fn page(
AuthIdentity(auth): AuthIdentity,
) -> crate::ApiResult<JsonLD<serde_json::Value>> {
let context = ctx.oid(&id);
let limit = page.batch.unwrap_or(50).min(50);
let offset = page.offset.unwrap_or(0);
let (limit, offset) = page.pagination();
let items = upub::Query::objects(auth.my_id())
.filter(auth.filter_objects())

View file

@ -21,8 +21,7 @@ pub async fn page(
AuthIdentity(auth): AuthIdentity,
Query(page): Query<Pagination>,
) -> crate::ApiResult<JsonLD<serde_json::Value>> {
let limit = page.batch.unwrap_or(20).min(50);
let offset = page.offset.unwrap_or(0);
let (limit, offset) = page.pagination();
let objects = upub::Query::hashtags()
.filter(auth.filter_objects())

View file

@ -14,8 +14,7 @@ pub async fn paginate_feed(
my_id: Option<i64>,
with_users: bool, // TODO ewww too many arguments for this weird function...
) -> crate::ApiResult<JsonLD<serde_json::Value>> {
let limit = page.batch.unwrap_or(20).min(50);
let offset = page.offset.unwrap_or(0);
let (limit, offset) = page.pagination();
let mut conditions = Condition::all()
.add(filter);