@@ -2,9 +2,9 @@ use std::{borrow::Cow, cell::RefCell};
22
33use nanorand:: { Rng , WyRand } ;
44use ntex:: util:: { Bytes , BytesMut } ;
5+ use smallvec:: SmallVec ;
56use tokio_postgres:: { connect, Client , Statement } ;
67use yarte:: TemplateBytesTrait ;
7- use smallvec:: SmallVec ;
88
99use super :: utils;
1010
@@ -108,27 +108,30 @@ impl PgConnection {
108108 let mut rng = nanorand:: tls_rng ( ) ;
109109 let mut ids = Vec :: with_capacity ( num) ;
110110 let mut numbers = Vec :: with_capacity ( num) ;
111- let mut queries = SmallVec :: < [ _ ; 32 ] > :: new ( ) ;
111+ let mut worlds = SmallVec :: < [ _ ; 32 ] > :: new ( ) ;
112112
113113 ( 0 ..num) . for_each ( |_| {
114114 let w_id = ( rng. generate :: < u32 > ( ) % 10_000 + 1 ) as i32 ;
115115 ids. push ( w_id) ;
116116 numbers. push ( ( rng. generate :: < u32 > ( ) % 10_000 + 1 ) as i32 ) ;
117- queries. push ( self . cl . query_one ( & self . world , & [ & w_id] ) ) ;
118117 } ) ;
119118 ids. sort ( ) ;
120119
121- for fut in queries. into_iter ( ) {
122- fut. await . unwrap ( ) ;
123- }
124-
125- let mut worlds = Vec :: with_capacity ( num) ;
126- for row in self . cl . query ( & self . updates , & [ & ids, & numbers] ) . await . unwrap ( ) {
127- worlds. push ( World {
128- id : row. get ( 0 ) ,
129- randomnumber : row. get ( 1 )
130- } ) ;
131- }
120+ let _ = ( 0 ..num)
121+ . map ( |idx| {
122+ worlds. push ( World {
123+ id : ids[ idx] ,
124+ randomnumber : numbers[ idx] ,
125+ } ) ;
126+ self . cl . query_one ( & self . world , & [ & ids[ idx] ] )
127+ } )
128+ . last ( )
129+ . unwrap ( )
130+ . await ;
131+ self . cl
132+ . query ( & self . updates , & [ & ids, & numbers] )
133+ . await
134+ . unwrap ( ) ;
132135
133136 let mut body = self . buf . borrow_mut ( ) ;
134137 utils:: reserve ( & mut body, 2 * 1024 ) ;
0 commit comments