mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-22 14:45:10 +00:00
See if different SQL query fixes performance regression (#4246)
* See if different SQL query fixes performance regression * Fix formatting * Hopefully fix failing federation test * Hopefully solve federation test problem * Use already-existing coalesce function * Update person_view.rs --------- Co-authored-by: SleeplessOne1917 <insomnia-void@protonmail.com> Co-authored-by: Dessalines <dessalines@users.noreply.github.com> Co-authored-by: Nutomic <me@nutomic.com> Co-authored-by: Dessalines <tyhou13@gmx.com>
This commit is contained in:
parent
30d58865b8
commit
8d52c7e7c7
|
@ -1,6 +1,5 @@
|
||||||
use crate::structs::PersonView;
|
use crate::structs::PersonView;
|
||||||
use diesel::{
|
use diesel::{
|
||||||
dsl::exists,
|
|
||||||
pg::Pg,
|
pg::Pg,
|
||||||
result::Error,
|
result::Error,
|
||||||
BoolExpressionMethods,
|
BoolExpressionMethods,
|
||||||
|
@ -13,7 +12,17 @@ use diesel_async::RunQueryDsl;
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::PersonId,
|
newtypes::PersonId,
|
||||||
schema::{local_user, person, person_aggregates},
|
schema::{local_user, person, person_aggregates},
|
||||||
utils::{fuzzy_search, limit_and_offset, now, DbConn, DbPool, ListFn, Queries, ReadFn},
|
utils::{
|
||||||
|
functions::coalesce,
|
||||||
|
fuzzy_search,
|
||||||
|
limit_and_offset,
|
||||||
|
now,
|
||||||
|
DbConn,
|
||||||
|
DbPool,
|
||||||
|
ListFn,
|
||||||
|
Queries,
|
||||||
|
ReadFn,
|
||||||
|
},
|
||||||
SortType,
|
SortType,
|
||||||
};
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
@ -48,21 +57,15 @@ fn post_to_person_sort_type(sort: SortType) -> PersonSortType {
|
||||||
|
|
||||||
fn queries<'a>(
|
fn queries<'a>(
|
||||||
) -> Queries<impl ReadFn<'a, PersonView, PersonId>, impl ListFn<'a, PersonView, ListMode>> {
|
) -> Queries<impl ReadFn<'a, PersonView, PersonId>, impl ListFn<'a, PersonView, ListMode>> {
|
||||||
let creator_is_admin = exists(
|
|
||||||
local_user::table.filter(
|
|
||||||
person::id
|
|
||||||
.eq(local_user::person_id)
|
|
||||||
.and(local_user::admin.eq(true)),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
let all_joins = move |query: person::BoxedQuery<'a, Pg>| {
|
let all_joins = move |query: person::BoxedQuery<'a, Pg>| {
|
||||||
query
|
query
|
||||||
.inner_join(person_aggregates::table)
|
.inner_join(person_aggregates::table)
|
||||||
|
.left_join(local_user::table)
|
||||||
.filter(person::deleted.eq(false))
|
.filter(person::deleted.eq(false))
|
||||||
.select((
|
.select((
|
||||||
person::all_columns,
|
person::all_columns,
|
||||||
person_aggregates::all_columns,
|
person_aggregates::all_columns,
|
||||||
creator_is_admin,
|
coalesce(local_user::admin.nullable(), false),
|
||||||
))
|
))
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -77,7 +80,7 @@ fn queries<'a>(
|
||||||
match mode {
|
match mode {
|
||||||
ListMode::Admins => {
|
ListMode::Admins => {
|
||||||
query = query
|
query = query
|
||||||
.filter(creator_is_admin.eq(true))
|
.filter(local_user::admin.eq(true))
|
||||||
.filter(person::deleted.eq(false))
|
.filter(person::deleted.eq(false))
|
||||||
.order_by(person::published);
|
.order_by(person::published);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit b3343aef72e5a7e5df34cf328b910ed798027270
|
Subproject commit 7a38baa7341cfa9299df5a80ebe42fe298380e40
|
Loading…
Reference in a new issue