From b9f0f33b3c52739f917210dcc61399a7878ff383 Mon Sep 17 00:00:00 2001 From: Natty Date: Mon, 15 Jan 2024 18:14:35 +0100 Subject: [PATCH] Resolve avatar and banner separately --- ext_calckey_model/src/note_model/mod.rs | 7 ++++--- ext_calckey_model/src/user_model.rs | 24 ++++++++++++++++-------- src/model/processing/note.rs | 10 ++++++---- src/model/processing/user.rs | 9 ++++++--- src/web/pagination.rs | 2 +- 5 files changed, 33 insertions(+), 19 deletions(-) diff --git a/ext_calckey_model/src/note_model/mod.rs b/ext_calckey_model/src/note_model/mod.rs index 586cacd..56e58ea 100644 --- a/ext_calckey_model/src/note_model/mod.rs +++ b/ext_calckey_model/src/note_model/mod.rs @@ -6,8 +6,9 @@ use sea_orm::{ Condition, EntityTrait, Iden, JoinType, QueryFilter, QueryOrder, QuerySelect, QueryTrait, Select, }; +use std::sync::Arc; -use ck::{note, note_reaction, user, user_note_pining}; +use ck::{note, note_reaction, user_note_pining}; use data::{sub_interaction_reaction, sub_interaction_renote, NoteData}; use magnetar_sdk::types::SpanFilter; @@ -35,9 +36,10 @@ pub trait NoteVisibilityFilterFactory: Send + Sync { fn with_note_and_user_tables(&self, note: &dyn Iden) -> SimpleExpr; } +#[derive(Clone)] pub struct NoteResolveOptions { pub ids: Option>, - pub visibility_filter: Box, + pub visibility_filter: Arc, pub time_range: Option, pub limit: Option, pub with_reply_target: bool, @@ -221,7 +223,6 @@ impl NoteResolver { // Add the note's author let user_tbl = note_tbl.join_str(USER); - q.add_aliased_columns::(&user_tbl); q.join_columns( JoinType::LeftJoin, note::Relation::User.with_from_alias(note_tbl), diff --git a/ext_calckey_model/src/user_model.rs b/ext_calckey_model/src/user_model.rs index 92b2e33..67cc5ae 100644 --- a/ext_calckey_model/src/user_model.rs +++ b/ext_calckey_model/src/user_model.rs @@ -106,8 +106,10 @@ impl ModelPagination for UserFollowRequestData { } } +#[derive(Clone)] pub struct UserResolveOptions { - pub with_avatar_and_banner: bool, + pub with_avatar: bool, + pub with_banner: bool, pub with_profile: bool, } @@ -130,7 +132,8 @@ impl UserResolver { q: &mut SelectStatement, user_tbl: &MagIden, UserResolveOptions { - with_avatar_and_banner, + with_avatar, + with_banner, with_profile, }: &UserResolveOptions, ) { @@ -148,19 +151,24 @@ impl UserResolver { ); } - if *with_avatar_and_banner { + if *with_avatar { let avatar_tbl = user_tbl.join_str(AVATAR); - let banner_tbl = user_tbl.join_str(BANNER); - q.add_aliased_columns::(&avatar_tbl) - .add_aliased_columns::(&banner_tbl); + q.add_aliased_columns::(&avatar_tbl); q.join_columns( JoinType::LeftJoin, user::Relation::DriveFile2.with_from_alias(user_tbl), &avatar_tbl, - ) - .join_columns( + ); + } + + if *with_banner { + let banner_tbl = user_tbl.join_str(BANNER); + + q.add_aliased_columns::(&banner_tbl); + + q.join_columns( JoinType::LeftJoin, user::Relation::DriveFile1.with_from_alias(user_tbl), &banner_tbl, diff --git a/src/model/processing/note.rs b/src/model/processing/note.rs index 1fe8051..02e349a 100644 --- a/src/model/processing/note.rs +++ b/src/model/processing/note.rs @@ -574,13 +574,14 @@ impl NoteModel { let Some(note) = note_resolver .get_one(&NoteResolveOptions { ids: Some(vec![id.to_owned()]), - visibility_filter: Box::new(NoteVisibilityFilterModel.new_note_visibility_filter( + visibility_filter: Arc::new(NoteVisibilityFilterModel.new_note_visibility_filter( ctx.self_user.as_deref().map(ck::user::Model::get_id), )), time_range: None, limit: None, user_options: UserResolveOptions { - with_avatar_and_banner: self.with_context, + with_avatar: self.with_context, + with_banner: false, with_profile: false, }, with_reply_target: self.with_context, @@ -613,13 +614,14 @@ impl NoteModel { let notes = note_resolver .get_many(&NoteResolveOptions { ids: None, - visibility_filter: Box::new(NoteVisibilityFilterModel.new_note_visibility_filter( + visibility_filter: Arc::new(NoteVisibilityFilterModel.new_note_visibility_filter( ctx.self_user.as_deref().map(ck::user::Model::get_id), )), time_range: None, limit: None, user_options: UserResolveOptions { - with_avatar_and_banner: self.with_context, + with_avatar: self.with_context, + with_banner: false, with_profile: false, }, with_reply_target: self.with_context, diff --git a/src/model/processing/user.rs b/src/model/processing/user.rs index 3b236d6..0e7ff34 100644 --- a/src/model/processing/user.rs +++ b/src/model/processing/user.rs @@ -596,7 +596,8 @@ impl UserModel { .get_user_resolver() .get_followers( &UserResolveOptions { - with_avatar_and_banner: true, + with_avatar: true, + with_banner: true, with_profile: true, }, id, @@ -641,7 +642,8 @@ impl UserModel { .get_user_resolver() .get_followees( &UserResolveOptions { - with_avatar_and_banner: true, + with_avatar: true, + with_banner: true, with_profile: true, }, id, @@ -684,7 +686,8 @@ impl UserModel { .get_user_resolver() .get_follow_requests( &UserResolveOptions { - with_avatar_and_banner: true, + with_avatar: true, + with_banner: true, with_profile: true, }, id, diff --git a/src/web/pagination.rs b/src/web/pagination.rs index cfd2a1b..662c7ac 100644 --- a/src/web/pagination.rs +++ b/src/web/pagination.rs @@ -12,7 +12,7 @@ use either::Either; use itertools::Itertools; use magnetar_calckey_model::sea_orm::prelude::async_trait::async_trait; use magnetar_core::web_model::rel::{RelNext, RelPrev}; -use magnetar_sdk::types::{NoFilter, PaginationShape, SpanFilter}; +use magnetar_sdk::types::{PaginationShape, SpanFilter}; use magnetar_sdk::util_types::U64Range; use serde::{Deserialize, Serialize}; use std::collections::HashMap;