Fixed FROM and filtering issues
ci/woodpecker/push/ociImagePush Pipeline was successful Details

This commit is contained in:
Natty 2024-01-08 01:14:19 +01:00
parent c6d84d6287
commit 811fecf99a
Signed by: natty
GPG Key ID: BF6CB659ADEE60EC
3 changed files with 25 additions and 20 deletions

View File

@ -78,6 +78,7 @@ pub(crate) fn joined_prefix(prefix: &str, suffix: &str) -> impl IntoIden {
pub(crate) trait EntityPrefixExt { pub(crate) trait EntityPrefixExt {
fn base_prefix_str(&self) -> String; fn base_prefix_str(&self) -> String;
fn base_prefix_alias(&self) -> Alias;
fn base_prefix(&self) -> impl IntoIden; fn base_prefix(&self) -> impl IntoIden;
} }
@ -86,7 +87,11 @@ impl<T: EntityTrait> EntityPrefixExt for T {
format!("{}.", self.table_name()) format!("{}.", self.table_name())
} }
fn base_prefix_alias(&self) -> Alias {
Alias::new(self.base_prefix_str())
}
fn base_prefix(&self) -> impl IntoIden { fn base_prefix(&self) -> impl IntoIden {
Alias::new(self.base_prefix_str()).into_iden() self.base_prefix_alias().into_iden()
} }
} }

View File

@ -1,7 +1,5 @@
use ext_calckey_model_migration::SelectStatement; use ext_calckey_model_migration::SelectStatement;
use sea_orm::sea_query::{ use sea_orm::sea_query::{Alias, Asterisk, Expr, IntoIden, Query, SelectExpr, SimpleExpr};
Alias, Asterisk, Expr, IntoCondition, IntoIden, Query, SelectExpr, SimpleExpr,
};
use sea_orm::{ use sea_orm::{
DbErr, EntityName, EntityTrait, FromQueryResult, Iden, JoinType, QueryFilter, QueryOrder, DbErr, EntityName, EntityTrait, FromQueryResult, Iden, JoinType, QueryFilter, QueryOrder,
QueryResult, QuerySelect, QueryTrait, Select, QueryResult, QuerySelect, QueryTrait, Select,
@ -206,7 +204,9 @@ impl NoteResolver {
options: &NoteResolveOptions, options: &NoteResolveOptions,
) -> Result<Option<NoteData>, CalckeyDbError> { ) -> Result<Option<NoteData>, CalckeyDbError> {
let select = self.resolve(options); let select = self.resolve(options);
let visibility_filter = options.visibility_filter.with_note_and_user_tables(None); let visibility_filter = options
.visibility_filter
.with_note_and_user_tables(Some(note::Entity.base_prefix_alias()));
let time_filter = options let time_filter = options
.time_range .time_range
.as_ref() .as_ref()
@ -229,7 +229,9 @@ impl NoteResolver {
options: &NoteResolveOptions, options: &NoteResolveOptions,
) -> Result<Vec<NoteData>, CalckeyDbError> { ) -> Result<Vec<NoteData>, CalckeyDbError> {
let select = self.resolve(options); let select = self.resolve(options);
let visibility_filter = options.visibility_filter.with_note_and_user_tables(None); let visibility_filter = options
.visibility_filter
.with_note_and_user_tables(Some(note::Entity.base_prefix_alias()));
let time_filter = options let time_filter = options
.time_range .time_range
.as_ref() .as_ref()
@ -325,33 +327,29 @@ impl NoteResolver {
} }
pub fn resolve(&self, options: &NoteResolveOptions) -> Select<note::Entity> { pub fn resolve(&self, options: &NoteResolveOptions) -> Select<note::Entity> {
let mut select = note::Entity::find();
let prefix = note::Entity.base_prefix_str(); let prefix = note::Entity.base_prefix_str();
let query = QuerySelect::query(&mut select); let mut select = Query::select();
query.clear_selects(); select.from_as(note::Entity, Alias::new(&prefix));
query.from_as(note::Entity, Alias::new(&prefix));
if let Some(pins_user) = &options.only_pins_from { if let Some(pins_user) = &options.only_pins_from {
select = select select
.join_as( .join_columns(
JoinType::InnerJoin, JoinType::InnerJoin,
note::Relation::UserNotePining.with_alias(Alias::new(&prefix)), note::Relation::UserNotePining.with_alias(Alias::new(&prefix)),
joined_prefix(&prefix, PIN), joined_prefix(&prefix, PIN),
) )
.filter( .and_where(
Expr::col(( Expr::col((
joined_prefix(&prefix, PIN), joined_prefix(&prefix, PIN),
user_note_pining::Column::UserId, user_note_pining::Column::UserId,
)) ))
.eq(pins_user) .eq(pins_user),
.into_condition(), );
)
} }
self.attach_note( self.attach_note(
QuerySelect::query(&mut select), &mut select,
&prefix, &prefix,
options.with_reply_target.then_some(1).unwrap_or_default(), options.with_reply_target.then_some(1).unwrap_or_default(),
options.with_renote_target.then_some(1).unwrap_or_default(), options.with_renote_target.then_some(1).unwrap_or_default(),
@ -359,6 +357,8 @@ impl NoteResolver {
&self.user_resolver, &self.user_resolver,
); );
select let mut ret_select = note::Entity::find();
*QuerySelect::query(&mut ret_select) = select;
ret_select
} }
} }

View File

@ -5,7 +5,7 @@ use crate::{
}; };
use ck::{drive_file, follow_request, following, user}; use ck::{drive_file, follow_request, following, user};
use ext_calckey_model_migration::{Alias, SelectStatement}; use ext_calckey_model_migration::{Alias, SelectStatement};
use sea_orm::{DbErr, EntityName, FromQueryResult, JoinType, QueryResult}; use sea_orm::{DbErr, FromQueryResult, JoinType, QueryResult};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]