WIP adding interior_refs endpoints

Ran into some limitations of sqlx while trying to bulk create interior_refs. I
also discovered how slow creating hundreds of rows in postgres is and I'm
planning on saving interior_refs data in a jsonb column instead which seems to
be much faster.
This commit is contained in:
2020-07-19 03:01:20 -04:00
parent 9985f123c9
commit 65e6ba1f8a
10 changed files with 272 additions and 14 deletions

View File

@@ -3,7 +3,7 @@ use std::convert::Infallible;
use warp::{Filter, Rejection, Reply};
use super::handlers;
use super::models::{ListParams, Owner, Shop};
use super::models::{InteriorRef, ListParams, Owner, Shop};
use super::Environment;
pub fn get_shop(env: Environment) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
@@ -61,6 +61,45 @@ pub fn list_owners(
.and_then(handlers::list_owners)
}
pub fn get_interior_ref(
env: Environment,
) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
warp::path!("interior_refs" / i32)
.and(warp::get())
.and(with_env(env))
.and_then(handlers::get_interior_ref)
}
pub fn create_interior_ref(
env: Environment,
) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
warp::path!("interior_refs")
.and(warp::post())
.and(json_body::<InteriorRef>())
.and(with_env(env))
.and_then(handlers::create_interior_ref)
}
pub fn list_interior_refs(
env: Environment,
) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
warp::path!("interior_refs")
.and(warp::get())
.and(warp::query::<ListParams>())
.and(with_env(env))
.and_then(handlers::list_interior_refs)
}
pub fn bulk_create_interior_refs(
env: Environment,
) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
warp::path!("interior_refs" / "bulk")
.and(warp::post())
.and(json_body::<Vec<InteriorRef>>())
.and(with_env(env))
.and_then(handlers::bulk_create_interior_refs)
}
fn with_env(env: Environment) -> impl Filter<Extract = (Environment,), Error = Infallible> + Clone {
warp::any().map(move || env.clone())
}
@@ -69,5 +108,5 @@ fn json_body<T>() -> impl Filter<Extract = (T,), Error = warp::Rejection> + Clon
where
T: Send + DeserializeOwned,
{
warp::body::content_length_limit(1024 * 16).and(warp::body::json())
warp::body::content_length_limit(1024 * 64).and(warp::body::json())
}