Skip to content

Commit 1235d94

Browse files
committed
remove all usage of explict pipeline
1 parent 29046e4 commit 1235d94

File tree

3 files changed

+50
-51
lines changed

3 files changed

+50
-51
lines changed

frameworks/Rust/xitca-web/Cargo.lock

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frameworks/Rust/xitca-web/Cargo.toml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,17 +95,17 @@ codegen-units = 1
9595
panic = "abort"
9696

9797
[patch.crates-io]
98-
xitca-postgres-diesel = { git = "https://github.com/fakeshadow/xitca-postgres-diesel", rev = "ffd222a" }
98+
xitca-postgres-diesel = { git = "https://github.com/fakeshadow/xitca-postgres-diesel", rev = "fb5dcba" }
9999
xitca-postgres-toasty = { git = "https://github.com/fakeshadow/xitca-postgres-toasty", rev = "04bedb8" }
100100

101101
# personal fork for efficient toasty engine fine tuned with pipelined xitca-postgres client
102102
toasty = { git = "https://github.com/fakeshadow/toasty", branch = "engine" }
103103
toasty-core = { git = "https://github.com/fakeshadow/toasty", branch = "engine" }
104104
toasty-sql = { git = "https://github.com/fakeshadow/toasty", branch = "engine" }
105105

106-
xitca-codegen = { git = "http://github.com/HFQR/xitca-web", rev = "91c6c31" }
107-
xitca-http = { git = "http://github.com/HFQR/xitca-web", rev = "91c6c31" }
108-
xitca-postgres = { git = "http://github.com/HFQR/xitca-web", rev = "91c6c31" }
109-
xitca-server = { git = "http://github.com/HFQR/xitca-web", rev = "91c6c31" }
110-
xitca-service = { git = "http://github.com/HFQR/xitca-web", rev = "91c6c31" }
111-
xitca-web = { git = "http://github.com/HFQR/xitca-web", rev = "91c6c31" }
106+
xitca-codegen = { git = "http://github.com/HFQR/xitca-web", rev = "244a06d" }
107+
xitca-http = { git = "http://github.com/HFQR/xitca-web", rev = "244a06d" }
108+
xitca-postgres = { git = "http://github.com/HFQR/xitca-web", rev = "244a06d" }
109+
xitca-server = { git = "http://github.com/HFQR/xitca-web", rev = "244a06d" }
110+
xitca-service = { git = "http://github.com/HFQR/xitca-web", rev = "244a06d" }
111+
xitca-web = { git = "http://github.com/HFQR/xitca-web", rev = "244a06d" }

frameworks/Rust/xitca-web/src/db.rs

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
#[path = "./db_util.rs"]
22
mod db_util;
33

4-
use core::cell::RefCell;
5-
6-
use xitca_io::bytes::BytesMut;
7-
use xitca_postgres::{Execute, iter::AsyncLendingIterator, pipeline::Pipeline, pool::Pool};
4+
use xitca_postgres::{Execute, iter::AsyncLendingIterator, pool::Pool};
85

96
use super::{
107
ser::{Fortune, Fortunes, World},
@@ -15,21 +12,21 @@ use db_util::{FORTUNE_STMT, UPDATE_STMT, WORLD_STMT, not_found};
1512

1613
pub struct Client {
1714
pool: Pool,
18-
shared: RefCell<(Rand, BytesMut)>,
15+
rng: core::cell::RefCell<Rand>,
1916
}
2017

2118
pub async fn create() -> HandleResult<Client> {
2219
Ok(Client {
2320
pool: Pool::builder(DB_URL).capacity(1).build()?,
24-
shared: Default::default(),
21+
rng: Default::default(),
2522
})
2623
}
2724

2825
impl Client {
2926
pub async fn get_world(&self) -> HandleResult<World> {
3027
let mut conn = self.pool.get().await?;
3128
let stmt = WORLD_STMT.execute(&mut conn).await?;
32-
let id = self.shared.borrow_mut().0.gen_id();
29+
let id = self.rng.borrow_mut().gen_id();
3330
let mut res = stmt.bind([id]).query(&conn.consume()).await?;
3431
let row = res.try_next().await?.ok_or_else(not_found)?;
3532
Ok(World::new(row.get(0), row.get(1)))
@@ -39,19 +36,21 @@ impl Client {
3936
let mut conn = self.pool.get().await?;
4037
let stmt = WORLD_STMT.execute(&mut conn).await?;
4138

42-
let mut res = {
43-
let (ref mut rng, ref mut buf) = *self.shared.borrow_mut();
44-
let mut pipe = Pipeline::with_capacity_from_buf(num as _, buf);
45-
rng.gen_multi()
46-
.take(num as _)
47-
.try_for_each(|id| stmt.bind([id]).query(&mut pipe))?;
48-
pipe.query(&conn.consume())?
49-
};
39+
let get = self
40+
.rng
41+
.borrow_mut()
42+
.gen_multi()
43+
.take(num as _)
44+
.map(|id| stmt.bind([id]).query(&conn))
45+
.collect::<Vec<_>>();
46+
47+
drop(conn);
5048

5149
let mut worlds = Vec::with_capacity(num as _);
5250

53-
while let Some(mut item) = res.try_next().await? {
54-
let row = item.try_next().await?.ok_or_else(not_found)?;
51+
for get in get {
52+
let mut res = get.await?;
53+
let row = res.try_next().await?.ok_or_else(not_found)?;
5554
worlds.push(World::new(row.get(0), row.get(1)));
5655
}
5756

@@ -63,32 +62,32 @@ impl Client {
6362
let world_stmt = WORLD_STMT.execute(&mut conn).await?;
6463
let update_stmt = UPDATE_STMT.execute(&mut conn).await?;
6564

66-
let (mut res, worlds) = {
67-
let (ref mut rng, ref mut buf) = *self.shared.borrow_mut();
68-
let mut pipe = Pipeline::with_capacity_from_buf((num + 1) as _, buf);
69-
65+
let (get, update, worlds) = {
66+
let mut rng = self.rng.borrow_mut();
7067
let mut ids = rng.gen_multi().take(num as _).collect::<Vec<_>>();
7168
ids.sort();
7269

73-
let (rngs, worlds) = ids
70+
let (get, rngs, worlds) = ids
7471
.iter()
7572
.cloned()
7673
.zip(rng.gen_multi())
7774
.map(|(id, rand)| {
78-
world_stmt.bind([id]).query(&mut pipe)?;
79-
HandleResult::Ok((rand, World::new(id, rand)))
75+
let get = world_stmt.bind([id]).query(&conn);
76+
(get, rand, World::new(id, rand))
8077
})
81-
.collect::<HandleResult<(Vec<_>, Vec<_>)>>()?;
82-
update_stmt.bind([&ids, &rngs]).query(&mut pipe)?;
83-
(pipe.query(&conn.consume())?, worlds)
78+
.collect::<(Vec<_>, Vec<_>, Vec<_>)>();
79+
80+
let update = update_stmt.bind([&ids, &rngs]).query(&conn.consume());
81+
82+
(get, update, worlds)
8483
};
8584

86-
while let Some(mut item) = res.try_next().await? {
87-
while let Some(row) = item.try_next().await? {
88-
let _rand = row.get::<i32>(1);
89-
}
85+
for fut in get {
86+
let _rand = fut.await?.try_next().await?.ok_or_else(not_found)?.get::<i32>(1);
9087
}
9188

89+
update.await?;
90+
9291
Ok(worlds)
9392
}
9493

0 commit comments

Comments
 (0)