Skip to content

Commit 245daef

Browse files
committed
optimize fastpath
1 parent fc35d42 commit 245daef

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

examples/drupal_loadtest.rs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@
2323
//! limitations under the License.
2424
2525
use rand::Rng;
26+
use regex::Regex;
2627
use scraper::{Html, Selector};
27-
use select::document::Document;
28-
use select::predicate::Name;
2928

3029
use goose::GooseState;
3130
use goose::goose::{GooseTaskSet, GooseClient, GooseTask};
@@ -80,23 +79,19 @@ fn drupal_loadtest_front_page(client: &mut GooseClient) {
8079
// Grab some static assets from the front page.
8180
match response {
8281
Ok(r) => {
83-
// Grab all src values from image tags.
84-
match Document::from_read(r) {
85-
Ok(d) => {
86-
d.find(Name("img"))
87-
.filter_map(|n| n.attr("src"))
88-
.for_each(|x| {
89-
// @TODO: once we're done comparing Goose to Locust, improve this
90-
// to do a better job of matching local assets
91-
if x.contains("/misc") || x.contains("/themes") {
92-
let _response = client.set_request_name("static asset").get(x);
93-
}
94-
});
82+
match r.text() {
83+
Ok(t) => {
84+
let re = Regex::new(r#"src="(.*?)""#).unwrap();
85+
for url in re.captures_iter(&t) {
86+
if url[1].contains("/misc") || url[1].contains("/themes") {
87+
let _response = client.set_request_name("static asset").get(&url[1]);
88+
}
89+
}
9590
},
9691
Err(e) => {
9792
eprintln!("failed to parse front page: {}", e);
9893
client.set_failure();
99-
}
94+
},
10095
}
10196
},
10297
Err(e) => {

0 commit comments

Comments
 (0)