2022-05-03 17:44:13 +00:00
|
|
|
use crate::structs::SiteView;
|
2024-09-16 15:18:16 +00:00
|
|
|
use diesel::{ExpressionMethods, JoinOnDsl, OptionalExtension, QueryDsl};
|
2022-11-09 10:05:00 +00:00
|
|
|
use diesel_async::RunQueryDsl;
|
2020-12-18 18:38:32 +00:00
|
|
|
use lemmy_db_schema::{
|
2022-10-27 09:24:07 +00:00
|
|
|
schema::{local_site, local_site_rate_limit, site, site_aggregates},
|
2022-11-09 10:05:00 +00:00
|
|
|
utils::{get_conn, DbPool},
|
2020-12-02 19:32:47 +00:00
|
|
|
};
|
2024-11-04 09:44:58 +00:00
|
|
|
use lemmy_utils::error::{LemmyErrorType, LemmyResult};
|
2020-12-02 19:32:47 +00:00
|
|
|
|
|
|
|
impl SiteView {
|
2024-09-16 15:18:16 +00:00
|
|
|
pub async fn read_local(pool: &mut DbPool<'_>) -> LemmyResult<Self> {
|
2022-11-09 10:05:00 +00:00
|
|
|
let conn = &mut get_conn(pool).await?;
|
2024-09-16 15:18:16 +00:00
|
|
|
Ok(
|
|
|
|
site::table
|
|
|
|
.inner_join(local_site::table)
|
|
|
|
.inner_join(
|
|
|
|
local_site_rate_limit::table.on(local_site::id.eq(local_site_rate_limit::local_site_id)),
|
|
|
|
)
|
|
|
|
.inner_join(site_aggregates::table)
|
|
|
|
.select((
|
|
|
|
site::all_columns,
|
|
|
|
local_site::all_columns,
|
|
|
|
local_site_rate_limit::all_columns,
|
|
|
|
site_aggregates::all_columns,
|
|
|
|
))
|
|
|
|
.first(conn)
|
|
|
|
.await
|
|
|
|
.optional()?
|
|
|
|
.ok_or(LemmyErrorType::LocalSiteNotSetup)?,
|
|
|
|
)
|
2020-12-02 19:32:47 +00:00
|
|
|
}
|
|
|
|
}
|