From b53c0737edb30d492d34770f07fa4c76fea54543 Mon Sep 17 00:00:00 2001 From: Chrislearn Young Date: Mon, 18 Sep 2023 23:08:37 +0800 Subject: [PATCH] [salvo] Upgrade to version 0.55.x (#8417) * [salvo] Upgrade to version 0.55.x * [salvo] drop connect after use --- frameworks/Rust/salvo/Cargo.toml | 2 +- frameworks/Rust/salvo/src/db_pg_pool.rs | 2 +- frameworks/Rust/salvo/src/main_diesel.rs | 4 ++++ frameworks/Rust/salvo/src/main_pg_pool.rs | 6 +++++- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/frameworks/Rust/salvo/Cargo.toml b/frameworks/Rust/salvo/Cargo.toml index 0a52c15d15c..82b6107eb70 100644 --- a/frameworks/Rust/salvo/Cargo.toml +++ b/frameworks/Rust/salvo/Cargo.toml @@ -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" diff --git a/frameworks/Rust/salvo/src/db_pg_pool.rs b/frameworks/Rust/salvo/src/db_pg_pool.rs index 560c9245ee1..bc1f546e922 100644 --- a/frameworks/Rust/salvo/src/db_pg_pool.rs +++ b/frameworks/Rust/salvo/src/db_pg_pool.rs @@ -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, Error> { +pub async fn fetch_all_fortunes(client: &Client, select: &Statement) -> Result, Error> { let rows: Vec = client.query(select, &[]).await.unwrap(); let mut fortunes: Vec = Vec::with_capacity(rows.capacity()); diff --git a/frameworks/Rust/salvo/src/main_diesel.rs b/frameworks/Rust/salvo/src/main_diesel.rs index ab7d343b96e..063b814e191 100644 --- a/frameworks/Rust/salvo/src/main_diesel.rs +++ b/frameworks/Rust/salvo/src/main_diesel.rs @@ -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::(&mut conn)?; + drop(conn); let data = serde_json::to_vec(&world).unwrap(); let headers = res.headers_mut(); @@ -75,6 +76,7 @@ async fn queries(req: &mut Request, res: &mut Response) -> Result<(), Error> { let w = world::table.find(id).get_result::(&mut conn)?; worlds.push(w); } + drop(conn); let data = serde_json::to_vec(&worlds)?; let headers = res.headers_mut(); @@ -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(); @@ -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::(&mut conn)?; + drop(conn); items.push(Fortune { id: 0, message: "Additional fortune added at request time.".to_string(), diff --git a/frameworks/Rust/salvo/src/main_pg_pool.rs b/frameworks/Rust/salvo/src/main_pg_pool.rs index b71e960a90c..75078c42ff1 100644 --- a/frameworks/Rust/salvo/src/main_pg_pool.rs +++ b/frameworks/Rust/salvo/src/main_pg_pool.rs @@ -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(); @@ -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 = future_worlds.try_collect().await?; + drop(client); let data = serde_json::to_vec(&worlds)?; let headers = res.headers_mut(); @@ -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 = future_world_updates.try_collect().await?; + drop(client); let data = serde_json::to_vec(&worlds)?; let headers = res.headers_mut(); @@ -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(),