diff --git a/backend/Cargo.toml b/backend/Cargo.toml index e9b5c95..b294c0c 100644 --- a/backend/Cargo.toml +++ b/backend/Cargo.toml @@ -15,7 +15,7 @@ lazy_static = "1.3.0" mime_guess = "1.8.7" openssl-probe = "0.1.2" pretty_env_logger = "0.3.0" -serde = "1.0.97" +serde = { version = "1.0.97", features = ["rc"] } serde_derive = "1.0.97" serde_json = "1.0.40" structopt = "0.2.18" diff --git a/backend/src/cache.rs b/backend/src/cache.rs index 9ca559d..dd0a36c 100644 --- a/backend/src/cache.rs +++ b/backend/src/cache.rs @@ -1,6 +1,7 @@ use std::{ collections::HashMap, hash::Hash, + sync::Arc, time::{Duration, Instant}, }; @@ -67,7 +68,7 @@ impl CacheEntry { } #[derive(Eq, PartialEq, Hash, Debug)] -pub(crate) struct Key(Service, String, String, String); +pub(crate) struct Key(Service, Arc, Arc, Arc); #[derive(Eq, PartialEq, Hash, Debug)] pub(crate) enum Service { @@ -77,7 +78,12 @@ pub(crate) enum Service { } impl Key { - pub(crate) fn new(service: Service, user: String, repo: String, branch: String) -> Self { + pub(crate) fn new( + service: Service, + user: Arc, + repo: Arc, + branch: Arc, + ) -> Self { Key(service, user, repo, branch) } } diff --git a/backend/src/data.rs b/backend/src/data.rs index 5439e68..7f36ab0 100644 --- a/backend/src/data.rs +++ b/backend/src/data.rs @@ -8,10 +8,10 @@ pub(crate) type State = Arc>>; #[derive(Deserialize, Debug)] pub(crate) struct FilePath { - pub(crate) user: String, - pub(crate) repo: String, - pub(crate) commit: String, - pub(crate) file: String, + pub(crate) user: Arc, + pub(crate) repo: Arc, + pub(crate) commit: Arc, + pub(crate) file: Arc, } impl FilePath { diff --git a/backend/src/main.rs b/backend/src/main.rs index 36a7177..20bd518 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -7,8 +7,6 @@ extern crate serde_derive; #[macro_use] extern crate structopt; -// TODO: cow instead of string - mod cache; mod cdn; mod config; @@ -51,7 +49,7 @@ fn proxy_file( .from_err() .and_then(move |response| match response.status() { StatusCode::OK => { - let mime = mime_guess::guess_mime_type(&data.file); + let mime = mime_guess::guess_mime_type(&*data.file); Ok(HttpResponse::Ok() .content_type(mime.to_string().as_str()) .set(CacheControl(vec![ @@ -134,7 +132,7 @@ fn serve_gist( .from_err() .and_then(move |response| match response.status() { StatusCode::OK => { - let mime = mime_guess::guess_mime_type(&data.file); + let mime = mime_guess::guess_mime_type(&*data.file); Ok(HttpResponse::Ok() .content_type(mime.to_string().as_str()) .set(CacheControl(vec![