chore: unify pagination options in trait
This commit is contained in:
parent
3bebd8bccf
commit
69071c1320
6 changed files with 13 additions and 10 deletions
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue