From f2f7b51fdc32047a38ee7f79ae6d4b6bbfb8ccea Mon Sep 17 00:00:00 2001 From: alemi Date: Mon, 22 Apr 2024 02:49:04 +0200 Subject: [PATCH] feat: order by publish date, not discovery also centralized ordering inside select_* queries --- src/model/addressing.rs | 8 +++++--- src/routes/activitypub/context.rs | 1 - src/routes/activitypub/inbox.rs | 1 - src/routes/activitypub/object/replies.rs | 1 - src/routes/activitypub/outbox.rs | 1 - src/routes/activitypub/user/inbox.rs | 1 - src/routes/activitypub/user/outbox.rs | 1 - src/routes/mastodon/accounts.rs | 3 +-- 8 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/model/addressing.rs b/src/model/addressing.rs index ad928c6..3837b09 100644 --- a/src/model/addressing.rs +++ b/src/model/addressing.rs @@ -1,5 +1,5 @@ use apb::{ActivityMut, ObjectMut}; -use sea_orm::{entity::prelude::*, FromQueryResult, Iterable, QuerySelect, SelectColumns}; +use sea_orm::{entity::prelude::*, FromQueryResult, Iterable, Order, QueryOrder, QuerySelect, SelectColumns}; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "addressing")] @@ -137,7 +137,8 @@ impl Entity { .distinct() .select_only() .join(sea_orm::JoinType::InnerJoin, Relation::Activity.def()) - .join(sea_orm::JoinType::LeftJoin, crate::model::activity::Relation::Object.def()); + .join(sea_orm::JoinType::LeftJoin, crate::model::activity::Relation::Object.def()) + .order_by(crate::model::activity::Column::Published, Order::Desc); for col in crate::model::activity::Column::iter() { select = select.select_column_as(col, format!("{}{}", crate::model::activity::Entity.table_name(), col.to_string())); @@ -155,7 +156,8 @@ impl Entity { .distinct() .select_only() .join(sea_orm::JoinType::InnerJoin, Relation::Object.def()) - .join(sea_orm::JoinType::LeftJoin, crate::model::object::Relation::Activity.def()); + .join(sea_orm::JoinType::LeftJoin, crate::model::object::Relation::Activity.def()) + .order_by(crate::model::object::Column::Published, Order::Desc); for col in crate::model::object::Column::iter() { select = select.select_column_as(col, format!("{}{}", crate::model::object::Entity.table_name(), col.to_string())); diff --git a/src/routes/activitypub/context.rs b/src/routes/activitypub/context.rs index 3709805..868975d 100644 --- a/src/routes/activitypub/context.rs +++ b/src/routes/activitypub/context.rs @@ -43,7 +43,6 @@ pub async fn page( let items = model::addressing::Entity::find_objects() .filter(auth.filter_condition()) .filter(model::object::Column::Context.eq(context)) - .order_by(model::addressing::Column::Published, Order::Desc) .limit(limit) .offset(offset) .into_model::() diff --git a/src/routes/activitypub/inbox.rs b/src/routes/activitypub/inbox.rs index 152a3b1..ba402e1 100644 --- a/src/routes/activitypub/inbox.rs +++ b/src/routes/activitypub/inbox.rs @@ -22,7 +22,6 @@ pub async fn page( let offset = page.offset.unwrap_or(0); let activities = model::addressing::Entity::find_activities() .filter(auth.filter_condition()) - .order_by(model::addressing::Column::Published, Order::Desc) .limit(limit) .offset(offset) .into_model::() diff --git a/src/routes/activitypub/object/replies.rs b/src/routes/activitypub/object/replies.rs index 04d4562..6dd2591 100644 --- a/src/routes/activitypub/object/replies.rs +++ b/src/routes/activitypub/object/replies.rs @@ -42,7 +42,6 @@ pub async fn page( .filter(auth.filter_condition()) .filter(model::object::Column::InReplyTo.eq(oid)) // TODO also limit to only local activities - .order_by(model::addressing::Column::Published, Order::Desc) .limit(limit) .offset(offset) .into_model::() diff --git a/src/routes/activitypub/outbox.rs b/src/routes/activitypub/outbox.rs index 9393e6d..189513f 100644 --- a/src/routes/activitypub/outbox.rs +++ b/src/routes/activitypub/outbox.rs @@ -18,7 +18,6 @@ pub async fn page( let items = model::addressing::Entity::find_activities() .filter(auth.filter_condition()) // TODO also limit to only local activities - .order_by(model::addressing::Column::Published, Order::Desc) .limit(limit) .offset(offset) .into_model::() diff --git a/src/routes/activitypub/user/inbox.rs b/src/routes/activitypub/user/inbox.rs index 6729ddd..0591c53 100644 --- a/src/routes/activitypub/user/inbox.rs +++ b/src/routes/activitypub/user/inbox.rs @@ -36,7 +36,6 @@ pub async fn page( let offset = page.offset.unwrap_or(0); let activities = model::addressing::Entity::find_activities() .filter(model::addressing::Column::Actor.eq(&uid)) - .order_by(model::addressing::Column::Published, Order::Desc) .offset(offset) .limit(limit) .into_model::() diff --git a/src/routes/activitypub/user/outbox.rs b/src/routes/activitypub/user/outbox.rs index 5c311d5..d51d42e 100644 --- a/src/routes/activitypub/user/outbox.rs +++ b/src/routes/activitypub/user/outbox.rs @@ -30,7 +30,6 @@ pub async fn page( let activities = model::addressing::Entity::find_activities() .filter(model::activity::Column::Actor.eq(&uid)) .filter(auth.filter_condition()) - .order_by(model::addressing::Column::Published, Order::Desc) .limit(limit) .offset(offset) .into_model::() diff --git a/src/routes/mastodon/accounts.rs b/src/routes/mastodon/accounts.rs index d893557..b8f106f 100644 --- a/src/routes/mastodon/accounts.rs +++ b/src/routes/mastodon/accounts.rs @@ -72,8 +72,7 @@ pub async fn statuses( let uid = ctx.uid(id); model::addressing::Entity::find_activities() .filter(model::activity::Column::Actor.eq(uid)) - .filter(auth.filter_condition()) - .order_by(model::addressing::Column::Published, Order::Desc); + .filter(auth.filter_condition()); todo!() }