From 2bd7682c7e048a3c98e6fa7847c36f4a4da26651 Mon Sep 17 00:00:00 2001 From: alemi Date: Fri, 27 Dec 2024 15:36:42 +0100 Subject: [PATCH] fix: feed should specify ordering, context by old --- upub/core/src/selector/query.rs | 2 -- upub/routes/src/activitypub/actor/inbox.rs | 4 +++- upub/routes/src/activitypub/actor/outbox.rs | 5 +++-- upub/routes/src/activitypub/application.rs | 4 +++- upub/routes/src/activitypub/inbox.rs | 4 +++- upub/routes/src/activitypub/object/context.rs | 4 +++- upub/routes/src/activitypub/object/replies.rs | 5 +++-- upub/routes/src/activitypub/outbox.rs | 2 ++ 8 files changed, 20 insertions(+), 10 deletions(-) diff --git a/upub/core/src/selector/query.rs b/upub/core/src/selector/query.rs index 02acf18..1b1082a 100644 --- a/upub/core/src/selector/query.rs +++ b/upub/core/src/selector/query.rs @@ -18,8 +18,6 @@ impl Query { .add(model::activity::Column::Id.is_not_null()) .add(model::object::Column::Id.is_not_null()) ) - .order_by(model::addressing::Column::Published, Order::Desc) - .order_by(model::activity::Column::Internal, Order::Desc) .select_only(); for col in model::activity::Column::iter() { diff --git a/upub/routes/src/activitypub/actor/inbox.rs b/upub/routes/src/activitypub/actor/inbox.rs index 52330b0..f9a37be 100644 --- a/upub/routes/src/activitypub/actor/inbox.rs +++ b/upub/routes/src/activitypub/actor/inbox.rs @@ -1,5 +1,5 @@ use axum::{http::StatusCode, extract::{Path, Query, State}, Json}; -use sea_orm::{ColumnTrait, Condition, QueryFilter, QuerySelect}; +use sea_orm::{ColumnTrait, Condition, QueryFilter, QueryOrder, QuerySelect}; use upub::{selector::{RichActivity, RichFillable}, Context}; @@ -45,6 +45,8 @@ pub async fn page( .filter(filter) .limit(limit) .offset(offset) + .order_by_desc(upub::model::addressing::Column::Published) + .order_by_desc(upub::model::activity::Column::Internal) .into_model::() .all(ctx.db()) .await? diff --git a/upub/routes/src/activitypub/actor/outbox.rs b/upub/routes/src/activitypub/actor/outbox.rs index 4cfb83d..d5a8d8d 100644 --- a/upub/routes/src/activitypub/actor/outbox.rs +++ b/upub/routes/src/activitypub/actor/outbox.rs @@ -1,5 +1,5 @@ use axum::{extract::{Path, Query, State}, http::StatusCode, Json}; -use sea_orm::{ActiveValue::{NotSet, Set}, ColumnTrait, Condition, EntityTrait, QueryFilter, QuerySelect}; +use sea_orm::{ActiveValue::{NotSet, Set}, ColumnTrait, Condition, EntityTrait, QueryFilter, QueryOrder, QuerySelect}; use upub::{model, selector::{RichActivity, RichFillable}, Context}; @@ -32,9 +32,10 @@ pub async fn page( // by default we want replies because servers don't know about our api and need to see everything let items = upub::Query::feed(auth.my_id(), page.replies.unwrap_or(true)) .filter(filter) - // TODO also limit to only local activities .limit(limit) .offset(offset) + .order_by_desc(upub::model::addressing::Column::Published) + .order_by_desc(upub::model::activity::Column::Internal) .into_model::() .all(ctx.db()) .await? diff --git a/upub/routes/src/activitypub/application.rs b/upub/routes/src/activitypub/application.rs index 22653a0..266df32 100644 --- a/upub/routes/src/activitypub/application.rs +++ b/upub/routes/src/activitypub/application.rs @@ -1,7 +1,7 @@ use apb::{LD, ActorMut, BaseMut, ObjectMut, PublicKeyMut}; use axum::{extract::{Path, Query, State}, http::HeaderMap, response::{IntoResponse, Redirect, Response}}; use reqwest::Method; -use sea_orm::{ColumnTrait, Condition, QueryFilter, QuerySelect}; +use sea_orm::{ColumnTrait, Condition, QueryFilter, QueryOrder, QuerySelect}; use upub::{selector::{RichFillable, RichObject}, traits::{Cloaker, Fetcher}, Context}; use crate::{builders::JsonLD, ApiError, AuthIdentity}; @@ -69,6 +69,8 @@ pub async fn search( .filter(filter) .limit(limit) .offset(offset) + .order_by_desc(upub::model::addressing::Column::Published) + .order_by_desc(upub::model::activity::Column::Internal) .into_model::() .all(ctx.db()) .await? diff --git a/upub/routes/src/activitypub/inbox.rs b/upub/routes/src/activitypub/inbox.rs index 6e08f06..4711257 100644 --- a/upub/routes/src/activitypub/inbox.rs +++ b/upub/routes/src/activitypub/inbox.rs @@ -1,6 +1,6 @@ use apb::{Activity, ActivityType, Base}; use axum::{extract::{Query, State}, http::StatusCode, Json}; -use sea_orm::{sea_query::IntoCondition, ActiveValue::{NotSet, Set}, ColumnTrait, EntityTrait, QueryFilter, QuerySelect}; +use sea_orm::{sea_query::IntoCondition, ActiveValue::{NotSet, Set}, ColumnTrait, EntityTrait, QueryFilter, QueryOrder, QuerySelect}; use upub::{model::job::JobType, selector::{RichActivity, RichFillable}, Context}; use crate::{AuthIdentity, Identity, builders::JsonLD}; @@ -25,6 +25,8 @@ pub async fn page( .filter(filter) .limit(limit) .offset(offset) + .order_by_desc(upub::model::addressing::Column::Published) + .order_by_desc(upub::model::activity::Column::Internal) .into_model::() .all(ctx.db()) .await? diff --git a/upub/routes/src/activitypub/object/context.rs b/upub/routes/src/activitypub/object/context.rs index 9c99462..0ae22d9 100644 --- a/upub/routes/src/activitypub/object/context.rs +++ b/upub/routes/src/activitypub/object/context.rs @@ -1,5 +1,5 @@ use axum::extract::{Path, Query, State}; -use sea_orm::{ColumnTrait, Condition, PaginatorTrait, QueryFilter, QuerySelect}; +use sea_orm::{ColumnTrait, Condition, PaginatorTrait, QueryFilter, QueryOrder, QuerySelect}; use upub::{model, selector::{RichFillable, RichObject}, Context}; use crate::{activitypub::Pagination, builders::JsonLD, AuthIdentity}; @@ -39,6 +39,8 @@ pub async fn page( .filter(filter) .limit(limit) .offset(offset) + .order_by_asc(upub::model::addressing::Column::Published) + .order_by_asc(upub::model::activity::Column::Internal) .into_model::() .all(ctx.db()) .await? diff --git a/upub/routes/src/activitypub/object/replies.rs b/upub/routes/src/activitypub/object/replies.rs index ef3a1dc..bd59499 100644 --- a/upub/routes/src/activitypub/object/replies.rs +++ b/upub/routes/src/activitypub/object/replies.rs @@ -1,6 +1,6 @@ use apb::{BaseMut, CollectionMut, LD}; use axum::extract::{Path, Query, State}; -use sea_orm::{ColumnTrait, Condition, PaginatorTrait, QueryFilter, QuerySelect}; +use sea_orm::{ColumnTrait, Condition, PaginatorTrait, QueryFilter, QueryOrder, QuerySelect}; use upub::{model, selector::{RichFillable, RichObject}, traits::Fetcher, Context}; use crate::{activitypub::{Pagination, TryFetch}, builders::JsonLD, AuthIdentity}; @@ -55,9 +55,10 @@ pub async fn page( let (limit, offset) = page.pagination(); let items = upub::Query::feed(auth.my_id(), page.replies.unwrap_or(true)) .filter(filter) - // TODO also limit to only local activities .limit(limit) .offset(offset) + .order_by_desc(upub::model::addressing::Column::Published) + .order_by_desc(upub::model::activity::Column::Internal) .into_model::() .all(ctx.db()) .await? diff --git a/upub/routes/src/activitypub/outbox.rs b/upub/routes/src/activitypub/outbox.rs index fd25e06..0a5b81f 100644 --- a/upub/routes/src/activitypub/outbox.rs +++ b/upub/routes/src/activitypub/outbox.rs @@ -23,6 +23,8 @@ pub async fn page( .filter(filter) .limit(limit) .offset(offset) + .order_by_desc(upub::model::addressing::Column::Published) + .order_by_desc(upub::model::activity::Column::Internal) .into_model::() .all(ctx.db()) .await?