Skip to content

Commit

Permalink
simplify db queries
Browse files Browse the repository at this point in the history
  • Loading branch information
Nutomic committed Jun 29, 2022
1 parent 7087ccf commit 3425e9e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
12 changes: 5 additions & 7 deletions crates/db_schema/src/impls/community.rs
Expand Up @@ -338,16 +338,14 @@ impl ApubActor for Community {
include_deleted: bool,
) -> Result<Community, Error> {
use crate::schema::community::dsl::*;
let q = community
let mut q = community
.into_boxed()
.filter(local.eq(true))
.filter(lower(name).eq(lower(community_name)));
if include_deleted {
q.first::<Self>(conn)
} else {
q.filter(deleted.eq(false))
.filter(removed.eq(false))
.first::<Self>(conn)
if !include_deleted {
q = q.filter(deleted.eq(false)).filter(removed.eq(false));
}
q.first::<Self>(conn)
}

fn read_from_name_and_domain(
Expand Down
10 changes: 5 additions & 5 deletions crates/db_schema/src/impls/person.rs
Expand Up @@ -310,14 +310,14 @@ impl ApubActor for Person {
from_name: &str,
include_deleted: bool,
) -> Result<Person, Error> {
let q = person
let mut q = person
.into_boxed()
.filter(local.eq(true))
.filter(lower(name).eq(lower(from_name)));
if include_deleted {
q.first::<Self>(conn)
} else {
q.filter(deleted.eq(false)).first::<Self>(conn)
if !include_deleted {
q = q.filter(deleted.eq(false))
}
q.first::<Self>(conn)
}

fn read_from_name_and_domain(
Expand Down

0 comments on commit 3425e9e

Please sign in to comment.