Skip to content

Commit aa2a93c

Browse files
fundonfranz1981
authored andcommitted
chore: use HashMap intead of Vec (TechEmpower#8090)
1 parent df03131 commit aa2a93c

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

frameworks/Rust/viz/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@ path = "src/main_diesel.rs"
2424
required-features = ["diesel", "diesel-async", "sailfish"]
2525

2626
[dependencies]
27-
viz = "0.4.9"
27+
viz = "0.4.10"
2828
hyper = "0.14.25"
2929
atoi = "2.0"
3030
serde = { version = "1.0", features = ["derive"] }
3131
nanorand = "0.7"
3232
thiserror = "1.0"
3333
futures-util = "0.3.27"
3434

35-
tokio = { version = "1.26", features = ["full"] }
36-
tokio-postgres = { version = "0.7.7", optional = true }
35+
tokio = { version = "1.27", features = ["full"] }
36+
tokio-postgres = { version = "0.7.8", optional = true }
3737
sqlx = { version = "0.6.3", features = [
3838
"postgres",
3939
"macros",

frameworks/Rust/viz/src/db_pg.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{borrow::Cow, fmt::Write, io, sync::Arc};
1+
use std::{borrow::Cow, collections::HashMap, fmt::Write, io, sync::Arc};
22

33
use futures_util::{stream::FuturesUnordered, TryFutureExt, TryStreamExt};
44
use nanorand::{Rng, WyRand};
@@ -37,7 +37,7 @@ pub struct PgConnection {
3737
client: Client,
3838
world: Statement,
3939
fortune: Statement,
40-
updates: Vec<Statement>,
40+
updates: HashMap<u16, Statement>,
4141
}
4242

4343
impl PgConnection {
@@ -54,7 +54,7 @@ impl PgConnection {
5454
});
5555

5656
let fortune = client.prepare("SELECT * FROM fortune").await.unwrap();
57-
let mut updates = Vec::new();
57+
let mut updates = HashMap::new();
5858

5959
for num in 1..=500u16 {
6060
let mut pl = 1;
@@ -77,7 +77,7 @@ impl PgConnection {
7777
q.pop();
7878
q.push(')');
7979

80-
updates.push(client.prepare(&q).await.unwrap());
80+
updates.insert(num, client.prepare(&q).await.unwrap());
8181
}
8282

8383
let world = client
@@ -137,6 +137,7 @@ impl PgConnection {
137137
}));
138138
}
139139

140+
let st = self.updates.get(&num).unwrap();
140141
let worlds = worlds.try_collect::<Vec<World>>().await?;
141142

142143
let num = num as usize;
@@ -151,7 +152,7 @@ impl PgConnection {
151152
params.push(&w.id);
152153
}
153154

154-
self.client.query(&self.updates[num - 1], &params).await?;
155+
self.client.query(st, &params).await?;
155156

156157
Ok(worlds)
157158
}

0 commit comments

Comments
 (0)