1
- use std:: { borrow:: Cow , fmt:: Write , io, sync:: Arc } ;
1
+ use std:: { borrow:: Cow , collections :: HashMap , fmt:: Write , io, sync:: Arc } ;
2
2
3
3
use futures_util:: { stream:: FuturesUnordered , TryFutureExt , TryStreamExt } ;
4
4
use nanorand:: { Rng , WyRand } ;
@@ -37,7 +37,7 @@ pub struct PgConnection {
37
37
client : Client ,
38
38
world : Statement ,
39
39
fortune : Statement ,
40
- updates : Vec < Statement > ,
40
+ updates : HashMap < u16 , Statement > ,
41
41
}
42
42
43
43
impl PgConnection {
@@ -54,7 +54,7 @@ impl PgConnection {
54
54
} ) ;
55
55
56
56
let fortune = client. prepare ( "SELECT * FROM fortune" ) . await . unwrap ( ) ;
57
- let mut updates = Vec :: new ( ) ;
57
+ let mut updates = HashMap :: new ( ) ;
58
58
59
59
for num in 1 ..=500u16 {
60
60
let mut pl = 1 ;
@@ -77,7 +77,7 @@ impl PgConnection {
77
77
q. pop ( ) ;
78
78
q. push ( ')' ) ;
79
79
80
- updates. push ( client. prepare ( & q) . await . unwrap ( ) ) ;
80
+ updates. insert ( num , client. prepare ( & q) . await . unwrap ( ) ) ;
81
81
}
82
82
83
83
let world = client
@@ -137,6 +137,7 @@ impl PgConnection {
137
137
} ) ) ;
138
138
}
139
139
140
+ let st = self . updates . get ( & num) . unwrap ( ) ;
140
141
let worlds = worlds. try_collect :: < Vec < World > > ( ) . await ?;
141
142
142
143
let num = num as usize ;
@@ -151,7 +152,7 @@ impl PgConnection {
151
152
params. push ( & w. id ) ;
152
153
}
153
154
154
- self . client . query ( & self . updates [ num - 1 ] , & params) . await ?;
155
+ self . client . query ( st , & params) . await ?;
155
156
156
157
Ok ( worlds)
157
158
}
0 commit comments