mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-23 12:51:18 +00:00
Cleaning up validate.
This commit is contained in:
parent
a8972b09b8
commit
ed1b728fdb
2 changed files with 9 additions and 10 deletions
|
@ -12,12 +12,11 @@ use crate::{
|
|||
utils::{get_conn, DbPool},
|
||||
};
|
||||
use diesel::{
|
||||
dsl::exists,
|
||||
insert_into,
|
||||
result::Error,
|
||||
select,
|
||||
ExpressionMethods,
|
||||
NotFound,
|
||||
OptionalExtension,
|
||||
QueryDsl,
|
||||
};
|
||||
use diesel_async::RunQueryDsl;
|
||||
|
@ -60,13 +59,12 @@ impl RemoteImage {
|
|||
|
||||
pub async fn validate(pool: &mut DbPool<'_>, link_: DbUrl) -> Result<(), Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
|
||||
let exists = select(exists(
|
||||
remote_image::table.filter(remote_image::link.eq(link_)),
|
||||
))
|
||||
.get_result::<bool>(conn)
|
||||
.await?;
|
||||
if exists {
|
||||
let res = remote_image::table
|
||||
.find(link_)
|
||||
.first::<RemoteImage>(conn)
|
||||
.await
|
||||
.optional()?;
|
||||
if res.is_some() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(NotFound)
|
||||
|
@ -79,6 +77,7 @@ impl ImageDetails {
|
|||
let conn = &mut get_conn(pool).await?;
|
||||
insert_into(image_details::table)
|
||||
.values(form)
|
||||
.on_conflict_do_nothing()
|
||||
.get_result::<Self>(conn)
|
||||
.await
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ services:
|
|||
|
||||
pictrs:
|
||||
restart: always
|
||||
image: asonix/pictrs:0.5.0-rc.2
|
||||
image: asonix/pictrs:0.5.13
|
||||
user: 991:991
|
||||
volumes:
|
||||
- ./volumes/pictrs_alpha:/mnt:Z
|
||||
|
|
Loading…
Reference in a new issue