Skip to content

Commit

Permalink
fix(tester): burst cache setting __v for each request url (#16)
Browse files Browse the repository at this point in the history
* Burst cache setting __v

* Fix lint errors
  • Loading branch information
igorbrasileiro committed Jun 14, 2024
1 parent da81559 commit d253d14
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ clap = "3.1.8"
csv = "1.1.6"
url = "2.4.0"
chrono = "0.4.26"
rand = "0.8.5"
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ async fn run_batch_tests(filename: &str, token: &str, number_of_runs: i8) -> boo

let mut csv_printer = printer::CSVPrinter::new();

for url in urls.flatten() {
for url in urls.map_while(Result::ok) {
println!("Testing {url}", url = url);

let test_finished = batch_tests(&url, token, number_of_runs, &mut csv_printer).await;
Expand Down
9 changes: 4 additions & 5 deletions src/tester.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use chrono::{DateTime, Utc};
// use chrono::{DateTime, Utc};
use futures::StreamExt;
use rand::prelude::*;
use url::Url;

use crate::{Audit, Audits, Categories, Category, LHResult, PSIResult, PSIResultValues, Strategy};
Expand Down Expand Up @@ -43,12 +44,10 @@ pub async fn get_page_audits(
number_of_runs: i8,
strategy: Strategy,
) -> Result<PSIResultValues, reqwest::Error> {
let now: DateTime<Utc> = Utc::now();
let timestamp = now.timestamp_millis().to_string();
let url_with_timestamp = add_query_param(url, "__v", &timestamp).unwrap();
let mut rng = rand::thread_rng();

let list_urls = (0..number_of_runs).map(|_| {
format!("https://www.googleapis.com/pagespeedonline/v5/runPagespeed?key={api_key}&url={url}&strategy={strategy}&category=performance", url = url_with_timestamp, api_key = token, strategy = strategy)
format!("https://www.googleapis.com/pagespeedonline/v5/runPagespeed?key={api_key}&url={url}&strategy={strategy}&category=performance", url = add_query_param(url, "__v", &format!("{}", rng.gen::<u32>())).unwrap(), api_key = token, strategy = strategy)
}).collect::<Vec<String>>();
let client = reqwest::Client::new();

Expand Down

0 comments on commit d253d14

Please sign in to comment.