Spiegel von
https://github.com/dani-garcia/vaultwarden.git
synchronisiert 2024-11-16 04:12:53 +01:00
use single hashmap instead of two for domain lookups
Dieser Commit ist enthalten in:
Ursprung
c0db0d8da0
Commit
3a66772077
2 geänderte Dateien mit 20 neuen und 19 gelöschten Zeilen
|
@ -365,6 +365,7 @@ use crate::db::{
|
|||
DbConn,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct HostInfo {
|
||||
pub base_url: String,
|
||||
pub origin: String,
|
||||
|
|
|
@ -8,6 +8,7 @@ use once_cell::sync::Lazy;
|
|||
use reqwest::Url;
|
||||
|
||||
use crate::{
|
||||
auth::HostInfo,
|
||||
db::DbConnType,
|
||||
error::Error,
|
||||
util::{get_env, get_env_bool, parse_experimental_client_feature_flags},
|
||||
|
@ -49,8 +50,7 @@ macro_rules! make_config {
|
|||
|
||||
_overrides: Vec<String>,
|
||||
|
||||
domain_hostmap: OnceLock<HostHashMap>,
|
||||
domain_origins: OnceLock<HostHashMap>,
|
||||
domain_hostmap: OnceLock<HashMap<String, HostInfo>>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Default, Deserialize, Serialize)]
|
||||
|
@ -347,8 +347,6 @@ macro_rules! make_config {
|
|||
|
||||
}
|
||||
|
||||
type HostHashMap = HashMap<String, String>;
|
||||
|
||||
//STRUCTURE:
|
||||
// /// Short description (without this they won't appear on the list)
|
||||
// group {
|
||||
|
@ -1121,7 +1119,6 @@ impl Config {
|
|||
_env,
|
||||
_usr,
|
||||
_overrides,
|
||||
domain_origins: OnceLock::new(),
|
||||
domain_hostmap: OnceLock::new(),
|
||||
}),
|
||||
})
|
||||
|
@ -1291,32 +1288,35 @@ impl Config {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn domain_origin(&self, host: &str) -> Option<String> {
|
||||
// This is done to prevent deadlock, when read-locking an rwlock twice
|
||||
let domains = self.domain_change_back();
|
||||
|
||||
self.inner.read().unwrap().domain_origins.get_or_init(|| {
|
||||
domains.split(',')
|
||||
.map(|d| {
|
||||
(extract_url_host(d), extract_url_origin(d))
|
||||
})
|
||||
.collect()
|
||||
}).get(host).cloned()
|
||||
}
|
||||
|
||||
pub fn host_to_domain(&self, host: &str) -> Option<String> {
|
||||
fn get_domain_hostmap(&self, host: &str) -> Option<HostInfo> {
|
||||
// This is done to prevent deadlock, when read-locking an rwlock twice
|
||||
let domains = self.domain_change_back();
|
||||
|
||||
self.inner.read().unwrap().domain_hostmap.get_or_init(|| {
|
||||
domains.split(',')
|
||||
.map(|d| {
|
||||
(extract_url_host(d), extract_url_path(d))
|
||||
let host_info = HostInfo {
|
||||
base_url: d.to_string(),
|
||||
origin: extract_url_origin(d),
|
||||
};
|
||||
|
||||
(extract_url_host(d), host_info)
|
||||
})
|
||||
.collect()
|
||||
}).get(host).cloned()
|
||||
}
|
||||
|
||||
pub fn domain_origin(&self, host: &str) -> Option<String> {
|
||||
self.get_domain_hostmap(host)
|
||||
.map(|v| v.origin)
|
||||
}
|
||||
|
||||
pub fn host_to_domain(&self, host: &str) -> Option<String> {
|
||||
self.get_domain_hostmap(host)
|
||||
.map(|v| v.base_url)
|
||||
}
|
||||
|
||||
// Yes this is a base_url
|
||||
// But the configuration precedent says, that we call this a domain.
|
||||
pub fn main_domain(&self) -> String {
|
||||
|
|
Laden …
In neuem Issue referenzieren