Skip to content

Commit

Permalink
[salvo] Upgrade to version 0.55.x (TechEmpower#8417)
Browse files Browse the repository at this point in the history
* [salvo] Upgrade to version 0.55.x

* [salvo] drop connect after use
  • Loading branch information
chrislearn authored Sep 18, 2023
1 parent e30b372 commit b53c073
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion frameworks/Rust/salvo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ markup = "0.13"
mongodb = { version = "2.4.0", features = ["zstd-compression", "snappy-compression", "zlib-compression"] }
once_cell = "1"
rand = { version = "0.8", features = ["min_const_gen", "small_rng"] }
salvo = { version = "0.54", default-features = false, features = ["anyhow", "http1", "affix"] }
salvo = { version = "0.55", default-features = false, features = ["anyhow", "http1", "affix"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
# smallvec = "1"
Expand Down
2 changes: 1 addition & 1 deletion frameworks/Rust/salvo/src/db_pg_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub async fn update_world(client: &Client, update: &Statement, random_id: i32, w
Ok(rows_modified)
}

pub async fn fetch_all_fortunes(client: Client, select: &Statement) -> Result<Vec<Fortune>, Error> {
pub async fn fetch_all_fortunes(client: &Client, select: &Statement) -> Result<Vec<Fortune>, Error> {
let rows: Vec<Row> = client.query(select, &[]).await.unwrap();

let mut fortunes: Vec<Fortune> = Vec::with_capacity(rows.capacity());
Expand Down
4 changes: 4 additions & 0 deletions frameworks/Rust/salvo/src/main_diesel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ async fn world_row(res: &mut Response) -> Result<(), Error> {
let random_id = rng.gen_range(1..10_001);
let mut conn = connect()?;
let world = world::table.find(random_id).first::<World>(&mut conn)?;
drop(conn);

let data = serde_json::to_vec(&world).unwrap();
let headers = res.headers_mut();
Expand All @@ -75,6 +76,7 @@ async fn queries(req: &mut Request, res: &mut Response) -> Result<(), Error> {
let w = world::table.find(id).get_result::<World>(&mut conn)?;
worlds.push(w);
}
drop(conn);

let data = serde_json::to_vec(&worlds)?;
let headers = res.headers_mut();
Expand Down Expand Up @@ -107,6 +109,7 @@ async fn updates(req: &mut Request, res: &mut Response) -> Result<(), Error> {
}
Ok(())
})?;
drop(conn);

let data = serde_json::to_vec(&worlds)?;
let headers = res.headers_mut();
Expand All @@ -120,6 +123,7 @@ async fn updates(req: &mut Request, res: &mut Response) -> Result<(), Error> {
async fn fortunes(res: &mut Response) -> Result<(), Error> {
let mut conn = connect()?;
let mut items = fortune::table.get_results::<Fortune>(&mut conn)?;
drop(conn);
items.push(Fortune {
id: 0,
message: "Additional fortune added at request time.".to_string(),
Expand Down
6 changes: 5 additions & 1 deletion frameworks/Rust/salvo/src/main_pg_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ async fn world_row(res: &mut Response) -> Result<(), Error> {
let client = pool().get().await?;
let select = prepare_fetch_world_by_id_statement(&client).await;
let world = fetch_world_by_id(&client, random_id, &select).await?;
drop(client);

let data = serde_json::to_vec(&world).unwrap();
let headers = res.headers_mut();
Expand All @@ -65,6 +66,7 @@ async fn queries(req: &mut Request, res: &mut Response) -> Result<(), Error> {
future_worlds.push(fetch_world_by_id(&client, w_id, &select));
}
let worlds: Vec<World> = future_worlds.try_collect().await?;
drop(client);

let data = serde_json::to_vec(&worlds)?;
let headers = res.headers_mut();
Expand Down Expand Up @@ -100,6 +102,7 @@ async fn updates(req: &mut Request, res: &mut Response) -> Result<(), Error> {
future_world_updates.push(update_world(&client, &update, random_id, w_id));
}
let _world_updates: Vec<u64> = future_world_updates.try_collect().await?;
drop(client);

let data = serde_json::to_vec(&worlds)?;
let headers = res.headers_mut();
Expand All @@ -113,7 +116,8 @@ async fn updates(req: &mut Request, res: &mut Response) -> Result<(), Error> {
async fn fortunes(res: &mut Response) -> Result<(), Error> {
let client = pool().get().await?;
let select = prepare_fetch_all_fortunes_statement(&client).await;
let mut items = fetch_all_fortunes(client, &select).await?;
let mut items = fetch_all_fortunes(&client, &select).await?;
drop(client);
items.push(Fortune {
id: 0,
message: "Additional fortune added at request time.".to_string(),
Expand Down

0 comments on commit b53c073

Please sign in to comment.