0
0
mirror of https://github.com/neon-mmd/websurfx.git synced 2024-11-26 15:58:21 -05:00

Compare commits

..

2 Commits

Author SHA1 Message Date
neon_arch
3f02f670bc
Merge 6aa99922a6 into 8d9b660eb1 2024-03-08 18:46:29 +00:00
neon_arch
6aa99922a6 perf: reduce the amount of clones, to_owneds & to_strings (#486) 2024-03-08 21:45:03 +03:00
9 changed files with 22 additions and 18 deletions

View File

@ -48,7 +48,7 @@ async fn main() -> std::io::Result<()> {
config.port,
);
let listener = TcpListener::bind((config.binding_ip.clone(), config.port))?;
let listener = TcpListener::bind((config.binding_ip.as_str(), config.port))?;
run(listener, config, cache)?.await
}

View File

@ -11,7 +11,6 @@ const REDIS_PIPELINE_SIZE: usize = 3;
/// A named struct which stores the redis Connection url address to which the client will
/// connect to.
#[derive(Clone)]
pub struct RedisCache {
/// It stores a pool of connections ready to be used.
connection_pool: Vec<ConnectionManager>,

View File

@ -9,7 +9,6 @@ use mlua::Lua;
use std::{collections::HashMap, fs, thread::available_parallelism};
/// A named struct which stores the parsed config file options.
#[derive(Clone)]
pub struct Config {
/// It stores the parsed port number option on which the server should launch.
pub port: u16,

View File

@ -69,8 +69,6 @@ pub fn run(
) -> std::io::Result<Server> {
let public_folder_path: &str = file_path(FileType::Theme)?;
let cloned_config_threads_opt: u8 = config.threads;
let cache = SHARED_CACHE.get_or_init(|| SharedCache::new(cache));
let server = HttpServer::new(move || {
@ -114,7 +112,7 @@ pub fn run(
.service(router::settings) // settings page
.default_service(web::route().to(router::not_found)) // error page
})
.workers(cloned_config_threads_opt as usize)
.workers(config.threads as usize)
// Start server on 127.0.0.1 with the user provided port number. for example 127.0.0.1:8080.
.listen(listener)?
.run();

View File

@ -10,7 +10,7 @@
/// order to allow the deserializing the json back to struct in aggregate function in
/// aggregator.rs and create a new struct out of it and then serialize it back to json and pass
/// it to the template files.
#[derive(Clone, Default)]
#[derive(Default)]
pub struct Style {
/// It stores the parsed theme option used to set a theme for the website.
pub theme: String,
@ -40,7 +40,6 @@ impl Style {
}
/// Configuration options for the aggregator.
#[derive(Clone)]
pub struct AggregatorConfig {
/// It stores the option to whether enable or disable random delays between
/// requests.
@ -48,7 +47,6 @@ pub struct AggregatorConfig {
}
/// Configuration options for the rate limiter middleware.
#[derive(Clone)]
pub struct RateLimiter {
/// The number of request that are allowed within a provided time limit.
pub number_of_requests: u8,

View File

@ -12,6 +12,7 @@ use error_stack::Report;
use futures::stream::FuturesUnordered;
use regex::Regex;
use reqwest::{Client, ClientBuilder};
use std::sync::Arc;
use std::time::{SystemTime, UNIX_EPOCH};
use std::{fs::File, io::BufRead};
use std::{
@ -98,13 +99,20 @@ pub async fn aggregate(
// create tasks for upstream result fetching
let tasks: FutureVec = FutureVec::new();
let query: Arc<String> = Arc::new(query.to_string());
for engine_handler in upstream_search_engines {
let (name, search_engine) = engine_handler.to_owned().into_name_engine();
let (name, search_engine) = engine_handler.clone().into_name_engine();
names.push(name);
let query: String = query.to_owned();
let query_partially_cloned = query.clone();
tasks.push(tokio::spawn(async move {
search_engine
.results(&query, page, user_agent, client, safe_search)
.results(
&query_partially_cloned,
page,
user_agent,
client,
safe_search,
)
.await
}));
}

View File

@ -55,7 +55,7 @@ pub fn engines(engine_names: &HashMap<String, bool>) -> Markup {
input type="checkbox" class="engine" checked;
span class="slider round"{}
}
(format!("{}{}",engine_name[..1].to_uppercase().to_owned(), engine_name[1..].to_owned()))
(format!("{}{}",&engine_name[..1].to_uppercase(), &engine_name[1..]))
}
}
@else {
@ -64,7 +64,7 @@ pub fn engines(engine_names: &HashMap<String, bool>) -> Markup {
input type="checkbox" class="engine";
span class="slider round"{}
}
(format!("{}{}",engine_name[..1].to_uppercase().to_owned(), engine_name[1..].to_owned()))
(format!("{}{}",&engine_name[..1], &engine_name[1..]))
}
}
}

View File

@ -36,7 +36,7 @@ fn style_option_list(
}
if style_type == "animations" {
style_option_names.push(("".to_owned(), "none".to_owned()))
style_option_names.push((String::default(), "none".to_owned()))
}
Ok(style_option_names)
@ -83,9 +83,11 @@ pub fn user_interface(
"Select the animation for your theme to be used in user interface"
}
select name="animations"{
@let default_animation = &String::default();
@let animation = animation.as_ref().unwrap_or(default_animation);
// Sets the user selected animation name from the config file as the first option in the selection list.
option value=(animation.as_ref().unwrap_or(&"".to_owned())){(animation.as_ref().unwrap_or(&"".to_owned()).replace('-'," "))}
@for (k,v) in style_option_list("animations", animation.as_ref().unwrap_or(&"".to_owned()))?{
option value=(animation){(animation.replace('-'," "))}
@for (k,v) in style_option_list("animations", animation)?{
option value=(k){(v)}
}
}

View File

@ -38,7 +38,7 @@ pub fn search(
small{(result.url)}
p{(PreEscaped(&result.description))}
.upstream_engines{
@for name in result.clone().engine{
@for name in &result.engine {
span{(name)}
}
}