Omit local instance from federated instances list (#3712)

Co-authored-by: Nutomic <me@nutomic.com>
Nutomic-patch-13
Bao 2023-07-27 05:12:18 -05:00 committed by GitHub
parent 9bfa86d162
commit 2d7b416652
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 1 deletions

View File

@ -1,7 +1,7 @@
use crate::{ use crate::{
diesel::dsl::IntervalDsl, diesel::dsl::IntervalDsl,
newtypes::InstanceId, newtypes::InstanceId,
schema::{federation_allowlist, federation_blocklist, instance}, schema::{federation_allowlist, federation_blocklist, instance, local_site, site},
source::instance::{Instance, InstanceForm}, source::instance::{Instance, InstanceForm},
utils::{get_conn, naive_now, DbPool}, utils::{get_conn, naive_now, DbPool},
}; };
@ -97,6 +97,10 @@ impl Instance {
pub async fn linked(pool: &mut DbPool<'_>) -> Result<Vec<Self>, Error> { pub async fn linked(pool: &mut DbPool<'_>) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?; let conn = &mut get_conn(pool).await?;
instance::table instance::table
// omit instance representing the local site
.left_join(site::table.inner_join(local_site::table))
.filter(local_site::id.is_null())
// omit instances in the blocklist
.left_join(federation_blocklist::table) .left_join(federation_blocklist::table)
.filter(federation_blocklist::id.is_null()) .filter(federation_blocklist::id.is_null())
.select(instance::all_columns) .select(instance::all_columns)