From 9b6b51889a186749c5b26ffcae5fd35a2b5e4085 Mon Sep 17 00:00:00 2001 From: alemi Date: Tue, 13 Aug 2024 20:32:49 +0200 Subject: [PATCH] fix: dont use builders for context --- upub/routes/src/activitypub/object/context.rs | 37 +++++++++++++------ 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/upub/routes/src/activitypub/object/context.rs b/upub/routes/src/activitypub/object/context.rs index 661e774..0e2366e 100644 --- a/upub/routes/src/activitypub/object/context.rs +++ b/upub/routes/src/activitypub/object/context.rs @@ -1,6 +1,6 @@ use axum::extract::{Path, Query, State}; -use sea_orm::{ColumnTrait, Condition, PaginatorTrait, QueryFilter}; -use upub::{model, Context}; +use sea_orm::{ColumnTrait, Condition, PaginatorTrait, QueryFilter, QuerySelect}; +use upub::{model, selector::{BatchFillable, RichActivity}, Context}; use crate::{activitypub::Pagination, builders::JsonLD, AuthIdentity, Identity}; @@ -39,14 +39,29 @@ pub async fn page( .add(model::object::Column::Context.eq(context)) .add(filter); + let limit = page.batch.unwrap_or(20).min(50); + let offset = page.offset.unwrap_or(0); - crate::builders::paginate_feed( - upub::url!(ctx, "/objects/{id}/context/page"), - filter, - ctx.db(), - page, - auth.my_id(), - false, - ) - .await + + let items = upub::Query::feed(auth.my_id(), true) + .filter(filter) + // TODO also limit to only local activities + .limit(limit) + .offset(offset) + .into_model::() + .all(ctx.db()) + .await? + .with_batched::(ctx.db()) + .await? + .with_batched::(ctx.db()) + .await? + .with_batched::(ctx.db()) + .await?; + + let items : Vec = items + .into_iter() + .map(|item| item.ap()) + .collect(); + + crate::builders::collection_page(&id, offset, limit, items) }