2022-05-03 17:44:13 +00:00
|
|
|
use crate::structs::SiteView;
|
2022-11-09 10:05:00 +00:00
|
|
|
use diesel::{result::Error, ExpressionMethods, JoinOnDsl, QueryDsl};
|
|
|
|
use diesel_async::RunQueryDsl;
|
2020-12-18 18:38:32 +00:00
|
|
|
use lemmy_db_schema::{
|
2022-05-03 17:44:13 +00:00
|
|
|
aggregates::structs::SiteAggregates,
|
2022-10-27 09:24:07 +00:00
|
|
|
schema::{local_site, local_site_rate_limit, site, site_aggregates},
|
|
|
|
source::{local_site::LocalSite, local_site_rate_limit::LocalSiteRateLimit, site::Site},
|
2022-11-09 10:05:00 +00:00
|
|
|
utils::{get_conn, DbPool},
|
2020-12-02 19:32:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
impl SiteView {
|
2023-07-11 13:09:59 +00:00
|
|
|
pub async fn read_local(pool: &mut DbPool<'_>) -> Result<Self, Error> {
|
2022-11-09 10:05:00 +00:00
|
|
|
let conn = &mut get_conn(pool).await?;
|
2022-10-27 09:24:07 +00:00
|
|
|
let (mut site, local_site, local_site_rate_limit, counts) = 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)),
|
|
|
|
)
|
2020-12-20 01:10:47 +00:00
|
|
|
.inner_join(site_aggregates::table)
|
2022-10-27 09:24:07 +00:00
|
|
|
.select((
|
|
|
|
site::all_columns,
|
|
|
|
local_site::all_columns,
|
|
|
|
local_site_rate_limit::all_columns,
|
|
|
|
site_aggregates::all_columns,
|
|
|
|
))
|
2022-11-09 10:05:00 +00:00
|
|
|
.first::<(Site, LocalSite, LocalSiteRateLimit, SiteAggregates)>(conn)
|
|
|
|
.await?;
|
2020-12-02 19:32:47 +00:00
|
|
|
|
2022-02-07 19:23:12 +00:00
|
|
|
site.private_key = None;
|
2022-10-27 09:24:07 +00:00
|
|
|
Ok(SiteView {
|
|
|
|
site,
|
|
|
|
local_site,
|
|
|
|
local_site_rate_limit,
|
|
|
|
counts,
|
|
|
|
})
|
2020-12-02 19:32:47 +00:00
|
|
|
}
|
|
|
|
}
|