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};
|
use upub::model::relation::Column::{Follower, Following, FollowerInstance, FollowingInstance};
|
||||||
let follow___ = if OUTGOING { "following" } else { "followers" };
|
let follow___ = if OUTGOING { "following" } else { "followers" };
|
||||||
|
|
||||||
let limit = page.batch.unwrap_or(100).min(500);
|
let (limit, offset) = page.pagination();
|
||||||
let offset = page.offset.unwrap_or(0);
|
|
||||||
|
|
||||||
let (user, config) = model::actor::Entity::find_by_ap_id(&ctx.uid(&id))
|
let (user, config) = model::actor::Entity::find_by_ap_id(&ctx.uid(&id))
|
||||||
.find_also_related(model::config::Entity)
|
.find_also_related(model::config::Entity)
|
||||||
|
|
|
@ -39,8 +39,7 @@ pub async fn page(
|
||||||
return Err(crate::ApiError::forbidden());
|
return Err(crate::ApiError::forbidden());
|
||||||
}
|
}
|
||||||
|
|
||||||
let limit = page.batch.unwrap_or(20).min(50);
|
let (limit, offset) = page.pagination();
|
||||||
let offset = page.offset.unwrap_or(0);
|
|
||||||
|
|
||||||
let activities = upub::Query::notifications(*internal, true)
|
let activities = upub::Query::notifications(*internal, true)
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
|
|
|
@ -94,6 +94,14 @@ pub struct Pagination {
|
||||||
pub replies: Option<bool>,
|
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)]
|
#[derive(Debug, serde::Deserialize)]
|
||||||
// TODO i don't really like how pleroma/mastodon do it actually, maybe change this?
|
// TODO i don't really like how pleroma/mastodon do it actually, maybe change this?
|
||||||
pub struct PaginatedSearch {
|
pub struct PaginatedSearch {
|
||||||
|
|
|
@ -27,8 +27,7 @@ pub async fn page(
|
||||||
AuthIdentity(auth): AuthIdentity,
|
AuthIdentity(auth): AuthIdentity,
|
||||||
) -> crate::ApiResult<JsonLD<serde_json::Value>> {
|
) -> crate::ApiResult<JsonLD<serde_json::Value>> {
|
||||||
let context = ctx.oid(&id);
|
let context = ctx.oid(&id);
|
||||||
let limit = page.batch.unwrap_or(50).min(50);
|
let (limit, offset) = page.pagination();
|
||||||
let offset = page.offset.unwrap_or(0);
|
|
||||||
|
|
||||||
let items = upub::Query::objects(auth.my_id())
|
let items = upub::Query::objects(auth.my_id())
|
||||||
.filter(auth.filter_objects())
|
.filter(auth.filter_objects())
|
||||||
|
|
|
@ -21,8 +21,7 @@ pub async fn page(
|
||||||
AuthIdentity(auth): AuthIdentity,
|
AuthIdentity(auth): AuthIdentity,
|
||||||
Query(page): Query<Pagination>,
|
Query(page): Query<Pagination>,
|
||||||
) -> crate::ApiResult<JsonLD<serde_json::Value>> {
|
) -> crate::ApiResult<JsonLD<serde_json::Value>> {
|
||||||
let limit = page.batch.unwrap_or(20).min(50);
|
let (limit, offset) = page.pagination();
|
||||||
let offset = page.offset.unwrap_or(0);
|
|
||||||
|
|
||||||
let objects = upub::Query::hashtags()
|
let objects = upub::Query::hashtags()
|
||||||
.filter(auth.filter_objects())
|
.filter(auth.filter_objects())
|
||||||
|
|
|
@ -14,8 +14,7 @@ pub async fn paginate_feed(
|
||||||
my_id: Option<i64>,
|
my_id: Option<i64>,
|
||||||
with_users: bool, // TODO ewww too many arguments for this weird function...
|
with_users: bool, // TODO ewww too many arguments for this weird function...
|
||||||
) -> crate::ApiResult<JsonLD<serde_json::Value>> {
|
) -> crate::ApiResult<JsonLD<serde_json::Value>> {
|
||||||
let limit = page.batch.unwrap_or(20).min(50);
|
let (limit, offset) = page.pagination();
|
||||||
let offset = page.offset.unwrap_or(0);
|
|
||||||
|
|
||||||
let mut conditions = Condition::all()
|
let mut conditions = Condition::all()
|
||||||
.add(filter);
|
.add(filter);
|
||||||
|
|
Loading…
Reference in a new issue