Fixed FROM and filtering issues
ci/woodpecker/push/ociImagePush Pipeline was successful
Details
ci/woodpecker/push/ociImagePush Pipeline was successful
Details
This commit is contained in:
parent
c6d84d6287
commit
811fecf99a
|
@ -78,6 +78,7 @@ pub(crate) fn joined_prefix(prefix: &str, suffix: &str) -> impl IntoIden {
|
|||
|
||||
pub(crate) trait EntityPrefixExt {
|
||||
fn base_prefix_str(&self) -> String;
|
||||
fn base_prefix_alias(&self) -> Alias;
|
||||
fn base_prefix(&self) -> impl IntoIden;
|
||||
}
|
||||
|
||||
|
@ -86,7 +87,11 @@ impl<T: EntityTrait> EntityPrefixExt for T {
|
|||
format!("{}.", self.table_name())
|
||||
}
|
||||
|
||||
fn base_prefix_alias(&self) -> Alias {
|
||||
Alias::new(self.base_prefix_str())
|
||||
}
|
||||
|
||||
fn base_prefix(&self) -> impl IntoIden {
|
||||
Alias::new(self.base_prefix_str()).into_iden()
|
||||
self.base_prefix_alias().into_iden()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
use ext_calckey_model_migration::SelectStatement;
|
||||
use sea_orm::sea_query::{
|
||||
Alias, Asterisk, Expr, IntoCondition, IntoIden, Query, SelectExpr, SimpleExpr,
|
||||
};
|
||||
use sea_orm::sea_query::{Alias, Asterisk, Expr, IntoIden, Query, SelectExpr, SimpleExpr};
|
||||
use sea_orm::{
|
||||
DbErr, EntityName, EntityTrait, FromQueryResult, Iden, JoinType, QueryFilter, QueryOrder,
|
||||
QueryResult, QuerySelect, QueryTrait, Select,
|
||||
|
@ -206,7 +204,9 @@ impl NoteResolver {
|
|||
options: &NoteResolveOptions,
|
||||
) -> Result<Option<NoteData>, CalckeyDbError> {
|
||||
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
|
||||
.time_range
|
||||
.as_ref()
|
||||
|
@ -229,7 +229,9 @@ impl NoteResolver {
|
|||
options: &NoteResolveOptions,
|
||||
) -> Result<Vec<NoteData>, CalckeyDbError> {
|
||||
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
|
||||
.time_range
|
||||
.as_ref()
|
||||
|
@ -325,33 +327,29 @@ impl NoteResolver {
|
|||
}
|
||||
|
||||
pub fn resolve(&self, options: &NoteResolveOptions) -> Select<note::Entity> {
|
||||
let mut select = note::Entity::find();
|
||||
|
||||
let prefix = note::Entity.base_prefix_str();
|
||||
|
||||
let query = QuerySelect::query(&mut select);
|
||||
query.clear_selects();
|
||||
query.from_as(note::Entity, Alias::new(&prefix));
|
||||
let mut select = Query::select();
|
||||
select.from_as(note::Entity, Alias::new(&prefix));
|
||||
|
||||
if let Some(pins_user) = &options.only_pins_from {
|
||||
select = select
|
||||
.join_as(
|
||||
select
|
||||
.join_columns(
|
||||
JoinType::InnerJoin,
|
||||
note::Relation::UserNotePining.with_alias(Alias::new(&prefix)),
|
||||
joined_prefix(&prefix, PIN),
|
||||
)
|
||||
.filter(
|
||||
.and_where(
|
||||
Expr::col((
|
||||
joined_prefix(&prefix, PIN),
|
||||
user_note_pining::Column::UserId,
|
||||
))
|
||||
.eq(pins_user)
|
||||
.into_condition(),
|
||||
)
|
||||
.eq(pins_user),
|
||||
);
|
||||
}
|
||||
|
||||
self.attach_note(
|
||||
QuerySelect::query(&mut select),
|
||||
&mut select,
|
||||
&prefix,
|
||||
options.with_reply_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,
|
||||
);
|
||||
|
||||
select
|
||||
let mut ret_select = note::Entity::find();
|
||||
*QuerySelect::query(&mut ret_select) = select;
|
||||
ret_select
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ use crate::{
|
|||
};
|
||||
use ck::{drive_file, follow_request, following, user};
|
||||
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};
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
|
|
Loading…
Reference in New Issue