mirror of
https://github.com/neon-mmd/websurfx.git
synced 2024-11-21 21:48:21 -05:00
feat: remove random delays when debug is set to true
This commit is contained in:
parent
eb44ff7cfa
commit
13632f1f99
@ -40,12 +40,13 @@ pub async fn aggregate(
|
|||||||
query: &str,
|
query: &str,
|
||||||
page: u32,
|
page: u32,
|
||||||
random_delay: bool,
|
random_delay: bool,
|
||||||
|
debug: bool,
|
||||||
) -> Result<SearchResults, Box<dyn std::error::Error>> {
|
) -> Result<SearchResults, Box<dyn std::error::Error>> {
|
||||||
let user_agent: String = random_user_agent();
|
let user_agent: String = random_user_agent();
|
||||||
let mut result_map: HashMap<String, RawSearchResult> = HashMap::new();
|
let mut result_map: HashMap<String, RawSearchResult> = HashMap::new();
|
||||||
|
|
||||||
// Add a random delay before making the request.
|
// Add a random delay before making the request.
|
||||||
if random_delay {
|
if random_delay || !debug {
|
||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::thread_rng();
|
||||||
let delay_secs = rng.gen_range(1..10);
|
let delay_secs = rng.gen_range(1..10);
|
||||||
std::thread::sleep(Duration::from_secs(delay_secs));
|
std::thread::sleep(Duration::from_secs(delay_secs));
|
||||||
|
@ -128,7 +128,7 @@ pub async fn search(
|
|||||||
}
|
}
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
let mut results_json: crate::search_results_handler::aggregation_models::SearchResults =
|
let mut results_json: crate::search_results_handler::aggregation_models::SearchResults =
|
||||||
aggregate(query, page, config.aggregator.random_delay).await?;
|
aggregate(query, page, config.aggregator.random_delay, config.debug).await?;
|
||||||
results_json.add_style(config.style.clone());
|
results_json.add_style(config.style.clone());
|
||||||
redis_cache
|
redis_cache
|
||||||
.cache_results(serde_json::to_string(&results_json)?, &page_url)?;
|
.cache_results(serde_json::to_string(&results_json)?, &page_url)?;
|
||||||
|
Loading…
Reference in New Issue
Block a user