Spaces:
Runtime error
Runtime error
neon_arch
commited on
Commit
•
13632f1
1
Parent(s):
eb44ff7
feat: remove random delays when debug is set to true
Browse files
src/search_results_handler/aggregator.rs
CHANGED
@@ -40,12 +40,13 @@ pub async fn aggregate(
|
|
40 |
query: &str,
|
41 |
page: u32,
|
42 |
random_delay: bool,
|
|
|
43 |
) -> Result<SearchResults, Box<dyn std::error::Error>> {
|
44 |
let user_agent: String = random_user_agent();
|
45 |
let mut result_map: HashMap<String, RawSearchResult> = HashMap::new();
|
46 |
|
47 |
// Add a random delay before making the request.
|
48 |
-
if random_delay {
|
49 |
let mut rng = rand::thread_rng();
|
50 |
let delay_secs = rng.gen_range(1..10);
|
51 |
std::thread::sleep(Duration::from_secs(delay_secs));
|
|
|
40 |
query: &str,
|
41 |
page: u32,
|
42 |
random_delay: bool,
|
43 |
+
debug: bool,
|
44 |
) -> Result<SearchResults, Box<dyn std::error::Error>> {
|
45 |
let user_agent: String = random_user_agent();
|
46 |
let mut result_map: HashMap<String, RawSearchResult> = HashMap::new();
|
47 |
|
48 |
// Add a random delay before making the request.
|
49 |
+
if random_delay || !debug {
|
50 |
let mut rng = rand::thread_rng();
|
51 |
let delay_secs = rng.gen_range(1..10);
|
52 |
std::thread::sleep(Duration::from_secs(delay_secs));
|
src/server/routes.rs
CHANGED
@@ -128,7 +128,7 @@ pub async fn search(
|
|
128 |
}
|
129 |
Err(_) => {
|
130 |
let mut results_json: crate::search_results_handler::aggregation_models::SearchResults =
|
131 |
-
aggregate(query, page, config.aggregator.random_delay).await?;
|
132 |
results_json.add_style(config.style.clone());
|
133 |
redis_cache
|
134 |
.cache_results(serde_json::to_string(&results_json)?, &page_url)?;
|
|
|
128 |
}
|
129 |
Err(_) => {
|
130 |
let mut results_json: crate::search_results_handler::aggregation_models::SearchResults =
|
131 |
+
aggregate(query, page, config.aggregator.random_delay, config.debug).await?;
|
132 |
results_json.add_style(config.style.clone());
|
133 |
redis_cache
|
134 |
.cache_results(serde_json::to_string(&results_json)?, &page_url)?;
|