From 050e40c03900827057ab5db2f6bbe971a6408fda Mon Sep 17 00:00:00 2001 From: "Adam T. Carpenter" Date: Sat, 31 Oct 2020 10:44:31 -0400 Subject: blocking on photo set generation since it hits the fs --- dichroism/src/handlers.rs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'dichroism/src/handlers.rs') diff --git a/dichroism/src/handlers.rs b/dichroism/src/handlers.rs index 7c1d302..0480abf 100644 --- a/dichroism/src/handlers.rs +++ b/dichroism/src/handlers.rs @@ -43,10 +43,12 @@ async fn patch_product( if let Some(data_uri) = patch.photo_data { // create new photo_set - let photo_set = image_service::generate_photo_set(&data_uri).map_err(|e| { - eprintln!("{}", e.to_string()); - HttpResponse::InternalServerError().body(e.to_string()) - })?; + let photo_set = web::block(move || image_service::generate_photo_set(&data_uri)) + .await + .map_err(|e| { + eprintln!("{}", e.to_string()); + HttpResponse::InternalServerError().body(e.to_string()) + })?; let conn = pool.get().map_err(to_internal_error)?; let photo_set = web::block(move || repo::store_photo_set(&conn, photo_set)) .await @@ -79,10 +81,13 @@ async fn post_product( let post = post.into_inner(); // create new photo_set - let photo_set = image_service::generate_photo_set(&post.photo_data).map_err(|e| { - eprintln!("{}", e.to_string()); - HttpResponse::InternalServerError().body(e.to_string()) - })?; + let data_uri = post.photo_data; + let photo_set = web::block(move || image_service::generate_photo_set(&data_uri)) + .await + .map_err(|e| { + eprintln!("{}", e.to_string()); + HttpResponse::InternalServerError().body(e.to_string()) + })?; let conn = pool.get().map_err(to_internal_error)?; let photo_set = web::block(move || repo::store_photo_set(&conn, photo_set)) .await -- cgit v1.2.3