|
@@ -68,7 +68,7 @@ impl PgConnection {
|
|
|
world,
|
|
|
updates,
|
|
|
rng: WyRand::new(),
|
|
|
- buf: RefCell::new(BytesMut::with_capacity(65535)),
|
|
|
+ buf: RefCell::new(BytesMut::with_capacity(10 * 1024 * 1024)),
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -80,7 +80,7 @@ impl PgConnection {
|
|
|
let row = self.cl.query_one(&self.world, &[&random_id]).await.unwrap();
|
|
|
|
|
|
let mut body = self.buf.borrow_mut();
|
|
|
- utils::reserve(&mut body, 8 * 1024);
|
|
|
+ utils::reserve(&mut body, 1024);
|
|
|
World {
|
|
|
id: row.get(0),
|
|
|
randomnumber: row.get(1),
|
|
@@ -107,7 +107,7 @@ impl PgConnection {
|
|
|
}
|
|
|
|
|
|
let mut body = self.buf.borrow_mut();
|
|
|
- utils::reserve(&mut body, 8 * 1024);
|
|
|
+ utils::reserve(&mut body, 2 * 1024);
|
|
|
body.put_u8(b'[');
|
|
|
worlds.iter().for_each(|w| {
|
|
|
w.to_bytes_mut(&mut *body);
|
|
@@ -119,7 +119,7 @@ impl PgConnection {
|
|
|
}
|
|
|
|
|
|
pub async fn update(&self, num: usize) -> Bytes {
|
|
|
- let mut rng = self.rng.clone();
|
|
|
+ let mut rng = nanorand::tls_rng();
|
|
|
let mut queries = SmallVec::<[_; 32]>::new();
|
|
|
(0..num).for_each(|_| {
|
|
|
let w_id = (rng.generate::<u32>() % 10_000 + 1) as i32;
|
|
@@ -146,7 +146,7 @@ impl PgConnection {
|
|
|
let _ = self.cl.query(&self.updates[num - 1], ¶ms).await;
|
|
|
|
|
|
let mut body = self.buf.borrow_mut();
|
|
|
- utils::reserve(&mut body, 8 * 1024);
|
|
|
+ utils::reserve(&mut body, 2 * 1024);
|
|
|
body.put_u8(b'[');
|
|
|
worlds.iter().for_each(|w| {
|
|
|
w.to_bytes_mut(&mut *body);
|
|
@@ -158,25 +158,20 @@ impl PgConnection {
|
|
|
}
|
|
|
|
|
|
pub async fn tell_fortune(&self) -> Bytes {
|
|
|
- let fut = self.cl.query_raw(&self.fortune, &[]);
|
|
|
+ let rows = self.cl.query_raw(&self.fortune, &[]).await.unwrap();
|
|
|
|
|
|
- let rows = fut.await.unwrap();
|
|
|
let mut fortunes: SmallVec<[_; 32]> = smallvec::smallvec![Fortune {
|
|
|
id: 0,
|
|
|
message: Cow::Borrowed("Additional fortune added at request time."),
|
|
|
}];
|
|
|
-
|
|
|
- for row in rows {
|
|
|
- fortunes.push(Fortune {
|
|
|
- id: row.get(0),
|
|
|
- message: Cow::Owned(row.get(1)),
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
+ fortunes.extend(rows.iter().map(|row| Fortune {
|
|
|
+ id: row.get(0),
|
|
|
+ message: Cow::Owned(row.get(1)),
|
|
|
+ }));
|
|
|
fortunes.sort_by(|it, next| it.message.cmp(&next.message));
|
|
|
|
|
|
let mut body = std::mem::replace(&mut *self.buf.borrow_mut(), BytesMut::new());
|
|
|
- utils::reserve(&mut body, 8 * 1024);
|
|
|
+ utils::reserve(&mut body, 4 * 1024);
|
|
|
ywrite_html!(body, "{{> fortune }}");
|
|
|
let result = body.split().freeze();
|
|
|
let _ = std::mem::replace(&mut *self.buf.borrow_mut(), body);
|