Skip to content

Commit 1602be4

Browse files
committed
Partially bring forward lobsters
Currently semi-blocked on rust-lang/rust#64477. Or rather, it would take a bunch of work to fix the last error in our code. Instead, there's a small change to std that would also fix it, so waiting on that: rust-lang/rust#64477 (comment)
1 parent 943e125 commit 1602be4

33 files changed

+3898
-4048
lines changed

Cargo.lock

+10-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

noria-benchmarks/lobsters/Cargo.toml

+4-3
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ orchestration = ["tsunami", "rusoto_core", "rusoto_sts", "failure", "ssh2", "she
99
default = []
1010

1111
[dependencies]
12-
trawler = "0.6.3"
12+
trawler = "0.7.0-alpha.1"
1313
mysql_async = "0.21.0-alpha.1"
14-
tokio = "0.1"
14+
tokio = "0.2.0-alpha.5"
1515
clap = "2.31"
16-
futures = "0.1"
16+
futures-core-preview = "0.3.0-alpha.18"
17+
futures-util-preview = "0.3.0-alpha.18"
1718
chrono = "0.4"
1819

1920
yansi = { version = "0.5", optional = true }
Original file line numberDiff line numberDiff line change
@@ -1,154 +1,143 @@
11
use chrono;
2-
use futures;
3-
use futures::Future;
42
use my;
53
use my::prelude::*;
4+
use std::future::Future;
65
use trawler::{CommentId, StoryId, UserId};
76

8-
pub(crate) fn handle<F>(
7+
pub(crate) async fn handle<F>(
98
c: F,
109
acting_as: Option<UserId>,
1110
id: CommentId,
1211
story: StoryId,
1312
parent: Option<CommentId>,
14-
) -> Box<dyn Future<Item = (my::Conn, bool), Error = my::error::Error> + Send>
13+
) -> Result<(my::Conn, bool), my::error::Error>
1514
where
16-
F: 'static + Future<Item = my::Conn, Error = my::error::Error> + Send,
15+
F: 'static + Future<Output = Result<my::Conn, my::error::Error>> + Send,
1716
{
17+
let c = c.await?;
1818
let user = acting_as.unwrap();
19-
Box::new(
20-
c.and_then(move |c| {
21-
c.first_exec::<_, _, my::Row>(
22-
"SELECT `stories`.* \
23-
FROM `stories` \
24-
WHERE `stories`.`short_id` = ?",
25-
(::std::str::from_utf8(&story[..]).unwrap(),),
26-
)
27-
.map(|(c, story)| (c, story.unwrap()))
28-
})
29-
.and_then(|(c, story)| {
30-
let author = story.get::<u32, _>("user_id").unwrap();
31-
let id = story.get::<u32, _>("id").unwrap();
32-
c.drop_exec(
33-
"SELECT `users`.* FROM `users` WHERE `users`.`id` = ?",
34-
(author,),
35-
)
36-
.map(move |c| (c, id))
37-
})
38-
.and_then(move |(c, story)| {
39-
let fut = if let Some(parent) = parent {
40-
// check that parent exists
41-
futures::future::Either::A(
42-
c.first_exec::<_, _, my::Row>(
43-
"SELECT `comments`.* FROM `comments` \
44-
WHERE `comments`.`story_id` = ? \
45-
AND `comments`.`short_id` = ?",
46-
(story, ::std::str::from_utf8(&parent[..]).unwrap()),
47-
)
48-
.map(move |(c, p)| {
49-
if let Some(p) = p {
50-
(
51-
c,
52-
Some((
53-
p.get::<u32, _>("id").unwrap(),
54-
p.get::<Option<u32>, _>("thread_id").unwrap(),
55-
)),
56-
)
57-
} else {
58-
eprintln!(
59-
"failed to find parent comment {} in story {}",
60-
::std::str::from_utf8(&parent[..]).unwrap(),
61-
story
62-
);
63-
(c, None)
64-
}
65-
}),
66-
)
67-
} else {
68-
futures::future::Either::B(futures::future::ok((c, None)))
69-
};
70-
fut.map(move |(c, parent)| (c, story, parent))
71-
})
72-
.map(|c| {
73-
// TODO: real site checks for recent comments by same author with same
74-
// parent to ensure we don't double-post accidentally
75-
c
76-
})
77-
.and_then(move |(c, story, parent)| {
78-
// check that short id is available
79-
c.drop_exec(
80-
"SELECT 1 AS one FROM `comments` \
81-
WHERE `comments`.`short_id` = ?",
82-
(::std::str::from_utf8(&id[..]).unwrap(),),
19+
let (c, story) = c
20+
.first_exec::<_, _, my::Row>(
21+
"SELECT `stories`.* \
22+
FROM `stories` \
23+
WHERE `stories`.`short_id` = ?",
24+
(::std::str::from_utf8(&story[..]).unwrap(),),
25+
)
26+
.await?;
27+
let story = story.unwrap();
28+
let author = story.get::<u32, _>("user_id").unwrap();
29+
let story = story.get::<u32, _>("id").unwrap();
30+
c = c
31+
.drop_exec(
32+
"SELECT `users`.* FROM `users` WHERE `users`.`id` = ?",
33+
(author,),
34+
)
35+
.await?;
36+
37+
let parent = if let Some(parent) = parent {
38+
// check that parent exists
39+
let (x, p) = c
40+
.first_exec::<_, _, my::Row>(
41+
"SELECT `comments`.* FROM `comments` \
42+
WHERE `comments`.`story_id` = ? \
43+
AND `comments`.`short_id` = ?",
44+
(story, ::std::str::from_utf8(&parent[..]).unwrap()),
8345
)
84-
.map(move |c| (c, story, parent))
85-
})
86-
.and_then(move |(c, story, parent)| {
87-
// TODO: real impl checks *new* short_id *again*
46+
.await?;
47+
c = x;
48+
49+
if let Some(p) = p {
50+
Some((
51+
p.get::<u32, _>("id").unwrap(),
52+
p.get::<Option<u32>, _>("thread_id").unwrap(),
53+
))
54+
} else {
55+
eprintln!(
56+
"failed to find parent comment {} in story {}",
57+
::std::str::from_utf8(&parent[..]).unwrap(),
58+
story
59+
);
60+
None
61+
}
62+
} else {
63+
None
64+
};
65+
66+
// TODO: real site checks for recent comments by same author with same
67+
// parent to ensure we don't double-post accidentally
68+
69+
// check that short id is available
70+
c = c
71+
.drop_exec(
72+
"SELECT 1 AS one FROM `comments` \
73+
WHERE `comments`.`short_id` = ?",
74+
(::std::str::from_utf8(&id[..]).unwrap(),),
75+
)
76+
.await?;
77+
78+
// TODO: real impl checks *new* short_id *again*
79+
80+
// NOTE: MySQL technically does everything inside this and_then in a transaction,
81+
// but let's be nice to it
82+
let now = chrono::Local::now().naive_local();
83+
let q = if let Some((parent, thread)) = parent {
84+
c.prep_exec(
85+
"INSERT INTO `comments` \
86+
(`created_at`, `updated_at`, `short_id`, `story_id`, \
87+
`user_id`, `parent_comment_id`, `thread_id`, \
88+
`comment`, `markeddown_comment`) \
89+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
90+
(
91+
now,
92+
now,
93+
::std::str::from_utf8(&id[..]).unwrap(),
94+
story,
95+
user,
96+
parent,
97+
thread,
98+
"moar benchmarking", // lorem ipsum?
99+
"<p>moar benchmarking</p>\n",
100+
),
101+
)
102+
.await?
103+
} else {
104+
c.prep_exec(
105+
"INSERT INTO `comments` \
106+
(`created_at`, `updated_at`, `short_id`, `story_id`, \
107+
`user_id`, `comment`, `markeddown_comment`) \
108+
VALUES (?, ?, ?, ?, ?, ?, ?)",
109+
(
110+
now,
111+
now,
112+
::std::str::from_utf8(&id[..]).unwrap(),
113+
story,
114+
user,
115+
"moar benchmarking", // lorem ipsum?
116+
"<p>moar benchmarking</p>\n",
117+
),
118+
)
119+
.await?
120+
};
121+
let comment = q.last_insert_id().unwrap();
122+
let c = q.drop_result().await?;
123+
// but why?!
124+
c = c
125+
.drop_exec(
126+
"SELECT `votes`.* FROM `votes` \
127+
WHERE `votes`.`user_id` = ? \
128+
AND `votes`.`story_id` = ? \
129+
AND `votes`.`comment_id` = ?",
130+
(user, story, comment),
131+
)
132+
.await?;
133+
c = c
134+
.drop_exec(
135+
"INSERT INTO `votes` \
136+
(`user_id`, `story_id`, `comment_id`, `vote`) \
137+
VALUES (?, ?, ?, ?)",
138+
(user, story, comment, 1),
139+
)
140+
.await?;
88141

89-
// NOTE: MySQL technically does everything inside this and_then in a transaction,
90-
// but let's be nice to it
91-
let now = chrono::Local::now().naive_local();
92-
if let Some((parent, thread)) = parent {
93-
futures::future::Either::A(c.prep_exec(
94-
"INSERT INTO `comments` \
95-
(`created_at`, `updated_at`, `short_id`, `story_id`, \
96-
`user_id`, `parent_comment_id`, `thread_id`, \
97-
`comment`, `markeddown_comment`) \
98-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
99-
(
100-
now,
101-
now,
102-
::std::str::from_utf8(&id[..]).unwrap(),
103-
story,
104-
user,
105-
parent,
106-
thread,
107-
"moar benchmarking", // lorem ipsum?
108-
"<p>moar benchmarking</p>\n",
109-
),
110-
))
111-
} else {
112-
futures::future::Either::B(c.prep_exec(
113-
"INSERT INTO `comments` \
114-
(`created_at`, `updated_at`, `short_id`, `story_id`, \
115-
`user_id`, `comment`, `markeddown_comment`) \
116-
VALUES (?, ?, ?, ?, ?, ?, ?)",
117-
(
118-
now,
119-
now,
120-
::std::str::from_utf8(&id[..]).unwrap(),
121-
story,
122-
user,
123-
"moar benchmarking", // lorem ipsum?
124-
"<p>moar benchmarking</p>\n",
125-
),
126-
))
127-
}
128-
.and_then(|q| {
129-
let comment = q.last_insert_id().unwrap();
130-
q.drop_result().map(move |t| (t, comment))
131-
})
132-
.and_then(move |(t, comment)| {
133-
// but why?!
134-
t.drop_exec(
135-
"SELECT `votes`.* FROM `votes` \
136-
WHERE `votes`.`user_id` = ? \
137-
AND `votes`.`story_id` = ? \
138-
AND `votes`.`comment_id` = ?",
139-
(user, story, comment),
140-
)
141-
.map(move |t| (t, comment))
142-
})
143-
.and_then(move |(t, comment)| {
144-
t.drop_exec(
145-
"INSERT INTO `votes` \
146-
(`user_id`, `story_id`, `comment_id`, `vote`) \
147-
VALUES (?, ?, ?, ?)",
148-
(user, story, comment, 1),
149-
)
150-
})
151-
})
152-
.map(|c| (c, false)),
153-
)
142+
Ok((c, false))
154143
}

0 commit comments

Comments
 (0)