mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-12-04 02:01:20 +00:00
d075acce43
- Diesel ordinarily throws an error when no results are returned for a single fetch, which is a bit confusing. This PR ensures that the missing value cases are all caught, and wrapped with new LemmyErrors, rather than diesel errors. - Fixes #4601
28 lines
859 B
Rust
28 lines
859 B
Rust
use crate::structs::SiteView;
|
|
use diesel::{result::Error, ExpressionMethods, JoinOnDsl, OptionalExtension, QueryDsl};
|
|
use diesel_async::RunQueryDsl;
|
|
use lemmy_db_schema::{
|
|
schema::{local_site, local_site_rate_limit, site, site_aggregates},
|
|
utils::{get_conn, DbPool},
|
|
};
|
|
|
|
impl SiteView {
|
|
pub async fn read_local(pool: &mut DbPool<'_>) -> Result<Option<Self>, Error> {
|
|
let conn = &mut get_conn(pool).await?;
|
|
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()
|
|
}
|
|
}
|