Cleaning up validate.

This commit is contained in:
Dessalines 2024-05-06 09:39:25 -04:00
parent a8972b09b8
commit ed1b728fdb
2 changed files with 9 additions and 10 deletions

View file

@ -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
}

View file

@ -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