Partial rollback of CompactString after benchmarking (or 'premature optimization is the root of all evil')
This commit is contained in:
@@ -6,7 +6,6 @@
|
||||
|
||||
use std::fmt::Debug;
|
||||
|
||||
use compact_str::{CompactString, ToCompactString};
|
||||
use directory::{
|
||||
QueryBy, ROLE_USER, Type,
|
||||
backend::{RcptType, internal::manage::ManageDirectory},
|
||||
@@ -57,10 +56,10 @@ async fn ldap_directory() {
|
||||
member_of: map_account_ids(base_store, vec!["sales"])
|
||||
.await
|
||||
.into_iter()
|
||||
.map(|v| v.to_compact_string())
|
||||
.map(|v| v.to_string())
|
||||
.collect(),
|
||||
emails: vec!["john@example.org".into(), "john.doe@example.org".into()],
|
||||
roles: vec![ROLE_USER.to_compact_string()],
|
||||
roles: vec![ROLE_USER.to_string()],
|
||||
..Default::default()
|
||||
}
|
||||
.into_sorted()
|
||||
@@ -87,7 +86,7 @@ async fn ldap_directory() {
|
||||
typ: Type::Individual,
|
||||
quota: 500000,
|
||||
emails: vec!["bill@example.org".into(),],
|
||||
roles: vec![ROLE_USER.to_compact_string()],
|
||||
roles: vec![ROLE_USER.to_string()],
|
||||
..Default::default()
|
||||
}
|
||||
.into_sorted()
|
||||
@@ -124,10 +123,10 @@ async fn ldap_directory() {
|
||||
member_of: map_account_ids(base_store, vec!["sales", "support"])
|
||||
.await
|
||||
.into_iter()
|
||||
.map(|v| v.to_compact_string())
|
||||
.map(|v| v.to_string())
|
||||
.collect(),
|
||||
emails: vec!["jane@example.org".into(),],
|
||||
roles: vec![ROLE_USER.to_compact_string()],
|
||||
roles: vec![ROLE_USER.to_string()],
|
||||
..Default::default()
|
||||
}
|
||||
.into_sorted()
|
||||
@@ -146,7 +145,7 @@ async fn ldap_directory() {
|
||||
name: "sales".into(),
|
||||
description: Some("sales".into()),
|
||||
typ: Type::Group,
|
||||
roles: vec![ROLE_USER.to_compact_string()],
|
||||
roles: vec![ROLE_USER.to_string()],
|
||||
..Default::default()
|
||||
}
|
||||
);
|
||||
@@ -228,11 +227,11 @@ async fn ldap_directory() {
|
||||
);
|
||||
compare_sorted(
|
||||
core.vrfy(&handle, "info", 0).await.unwrap(),
|
||||
Vec::<CompactString>::new(),
|
||||
Vec::<String>::new(),
|
||||
);
|
||||
compare_sorted(
|
||||
core.vrfy(&handle, "invalid", 0).await.unwrap(),
|
||||
Vec::<CompactString>::new(),
|
||||
Vec::<String>::new(),
|
||||
);
|
||||
|
||||
// EXPN
|
||||
|
||||
@@ -12,7 +12,6 @@ pub mod smtp;
|
||||
pub mod sql;
|
||||
|
||||
use common::{Core, Server, config::smtp::session::AddressMapping};
|
||||
use compact_str::{CompactString, ToCompactString, format_compact};
|
||||
use directory::{
|
||||
Directories, Principal, Type,
|
||||
backend::internal::{PrincipalField, PrincipalSet, manage::ManageDirectory},
|
||||
@@ -323,13 +322,13 @@ pub struct TestPrincipal {
|
||||
pub id: u32,
|
||||
pub typ: Type,
|
||||
pub quota: u64,
|
||||
pub name: CompactString,
|
||||
pub secrets: Vec<CompactString>,
|
||||
pub emails: Vec<CompactString>,
|
||||
pub member_of: Vec<CompactString>,
|
||||
pub roles: Vec<CompactString>,
|
||||
pub lists: Vec<CompactString>,
|
||||
pub description: Option<CompactString>,
|
||||
pub name: String,
|
||||
pub secrets: Vec<String>,
|
||||
pub emails: Vec<String>,
|
||||
pub member_of: Vec<String>,
|
||||
pub roles: Vec<String>,
|
||||
pub lists: Vec<String>,
|
||||
pub description: Option<String>,
|
||||
}
|
||||
|
||||
impl DirectoryTest {
|
||||
@@ -547,21 +546,9 @@ impl From<Principal> for TestPrincipal {
|
||||
id: value.id(),
|
||||
typ: value.typ(),
|
||||
quota: value.quota(),
|
||||
member_of: value
|
||||
.member_of()
|
||||
.iter()
|
||||
.map(|v| v.to_compact_string())
|
||||
.collect(),
|
||||
roles: value
|
||||
.roles()
|
||||
.iter()
|
||||
.map(|v| v.to_compact_string())
|
||||
.collect(),
|
||||
lists: value
|
||||
.lists()
|
||||
.iter()
|
||||
.map(|v| v.to_compact_string())
|
||||
.collect(),
|
||||
member_of: value.member_of().iter().map(|v| v.to_string()).collect(),
|
||||
roles: value.roles().iter().map(|v| v.to_string()).collect(),
|
||||
lists: value.lists().iter().map(|v| v.to_string()).collect(),
|
||||
name: value.name,
|
||||
secrets: value.secrets,
|
||||
emails: value.emails,
|
||||
@@ -585,23 +572,23 @@ impl From<TestPrincipal> for PrincipalSet {
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Hash)]
|
||||
pub enum Item {
|
||||
IsAccount(CompactString),
|
||||
IsAccount(String),
|
||||
Authenticate(Credentials<String>),
|
||||
Verify(CompactString),
|
||||
Expand(CompactString),
|
||||
Verify(String),
|
||||
Expand(String),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum LookupResult {
|
||||
True,
|
||||
False,
|
||||
Values(Vec<CompactString>),
|
||||
Values(Vec<String>),
|
||||
}
|
||||
|
||||
impl Item {
|
||||
pub fn append(&self, append: usize) -> Self {
|
||||
match self {
|
||||
Item::IsAccount(str) => Item::IsAccount(format_compact!("{append}{str}")),
|
||||
Item::IsAccount(str) => Item::IsAccount(format!("{append}{str}")),
|
||||
Item::Authenticate(str) => Item::Authenticate(match str {
|
||||
Credentials::Plain { username, secret } => Credentials::Plain {
|
||||
username: username.to_string(),
|
||||
@@ -615,8 +602,8 @@ impl Item {
|
||||
secret: format!("{append}{secret}"),
|
||||
},
|
||||
}),
|
||||
Item::Verify(str) => Item::Verify(format_compact!("{append}{str}")),
|
||||
Item::Expand(str) => Item::Expand(format_compact!("{append}{str}")),
|
||||
Item::Verify(str) => Item::Verify(format!("{append}{str}")),
|
||||
Item::Expand(str) => Item::Expand(format!("{append}{str}")),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -637,9 +624,9 @@ impl LookupResult {
|
||||
let mut r = Vec::with_capacity(v.len());
|
||||
for (pos, val) in v.iter().enumerate() {
|
||||
r.push(if pos == 0 {
|
||||
format_compact!("{append}{val}")
|
||||
format!("{append}{val}")
|
||||
} else {
|
||||
val.to_compact_string()
|
||||
val.to_string()
|
||||
});
|
||||
}
|
||||
LookupResult::Values(r)
|
||||
@@ -658,8 +645,8 @@ impl From<bool> for LookupResult {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Vec<CompactString>> for LookupResult {
|
||||
fn from(v: Vec<CompactString>) -> Self {
|
||||
impl From<Vec<String>> for LookupResult {
|
||||
fn from(v: Vec<String>) -> Self {
|
||||
LookupResult::Values(v)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,13 +4,13 @@
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL
|
||||
*/
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use super::dummy_tls_acceptor;
|
||||
use crate::directory::{DirectoryTest, Item, LookupResult};
|
||||
use common::listener::limiter::{ConcurrencyLimiter, InFlight};
|
||||
use compact_str::ToCompactString;
|
||||
use directory::{QueryBy, backend::RcptType};
|
||||
use mail_parser::decoders::base64::base64_decode;
|
||||
use mail_send::Credentials;
|
||||
use std::sync::Arc;
|
||||
use tokio::{
|
||||
io::{AsyncReadExt, AsyncWriteExt},
|
||||
net::{TcpListener, TcpStream},
|
||||
@@ -18,10 +18,6 @@ use tokio::{
|
||||
};
|
||||
use tokio_rustls::TlsAcceptor;
|
||||
|
||||
use crate::directory::{DirectoryTest, Item, LookupResult};
|
||||
|
||||
use super::dummy_tls_acceptor;
|
||||
|
||||
#[tokio::test]
|
||||
async fn lmtp_directory() {
|
||||
// Spawn mock LMTP server
|
||||
@@ -308,7 +304,7 @@ async fn accept_smtp(
|
||||
.split(',')
|
||||
.filter_map(|s| {
|
||||
if !s.is_empty() {
|
||||
s.to_compact_string().into()
|
||||
s.to_string().into()
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL
|
||||
*/
|
||||
|
||||
use compact_str::{CompactString, ToCompactString};
|
||||
use directory::{
|
||||
QueryBy, ROLE_USER, Type,
|
||||
backend::{RcptType, internal::manage::ManageDirectory},
|
||||
@@ -133,14 +132,14 @@ async fn sql_directory() {
|
||||
member_of: map_account_ids(base_store, vec!["sales"])
|
||||
.await
|
||||
.into_iter()
|
||||
.map(|v| v.to_compact_string())
|
||||
.map(|v| v.to_string())
|
||||
.collect(),
|
||||
emails: vec![
|
||||
"john@example.org".into(),
|
||||
"jdoe@example.org".into(),
|
||||
"john.doe@example.org".into()
|
||||
],
|
||||
roles: vec![ROLE_USER.to_compact_string()],
|
||||
roles: vec![ROLE_USER.to_string()],
|
||||
..Default::default()
|
||||
}
|
||||
);
|
||||
@@ -167,7 +166,7 @@ async fn sql_directory() {
|
||||
typ: Type::Individual,
|
||||
quota: 500000,
|
||||
emails: vec!["bill@example.org".into(),],
|
||||
roles: vec![ROLE_USER.to_compact_string()],
|
||||
roles: vec![ROLE_USER.to_string()],
|
||||
..Default::default()
|
||||
}
|
||||
);
|
||||
@@ -190,7 +189,7 @@ async fn sql_directory() {
|
||||
description: Some("Administrator".into()),
|
||||
secrets: vec!["very_secret".into()],
|
||||
typ: Type::Individual,
|
||||
roles: vec![ROLE_USER.to_compact_string()],
|
||||
roles: vec![ROLE_USER.to_string()],
|
||||
..Default::default()
|
||||
}
|
||||
);
|
||||
@@ -225,10 +224,10 @@ async fn sql_directory() {
|
||||
member_of: map_account_ids(base_store, vec!["sales", "support"])
|
||||
.await
|
||||
.into_iter()
|
||||
.map(|v| v.to_compact_string())
|
||||
.map(|v| v.to_string())
|
||||
.collect(),
|
||||
emails: vec!["jane@example.org".into(),],
|
||||
roles: vec![ROLE_USER.to_compact_string()],
|
||||
roles: vec![ROLE_USER.to_string()],
|
||||
..Default::default()
|
||||
}
|
||||
);
|
||||
@@ -246,7 +245,7 @@ async fn sql_directory() {
|
||||
name: "sales".into(),
|
||||
description: Some("Sales Team".into()),
|
||||
typ: Type::Group,
|
||||
roles: vec![ROLE_USER.to_compact_string()],
|
||||
roles: vec![ROLE_USER.to_string()],
|
||||
..Default::default()
|
||||
}
|
||||
);
|
||||
@@ -316,26 +315,26 @@ async fn sql_directory() {
|
||||
// VRFY
|
||||
assert_eq!(
|
||||
core.vrfy(&handle, "jane", 0).await.unwrap(),
|
||||
vec!["jane@example.org".to_compact_string()]
|
||||
vec!["jane@example.org".to_string()]
|
||||
);
|
||||
assert_eq!(
|
||||
core.vrfy(&handle, "john", 0).await.unwrap(),
|
||||
vec![
|
||||
"john.doe@example.org".to_compact_string(),
|
||||
"john@example.org".to_compact_string(),
|
||||
"john.doe@example.org".to_string(),
|
||||
"john@example.org".to_string(),
|
||||
]
|
||||
);
|
||||
assert_eq!(
|
||||
core.vrfy(&handle, "jane+alias@example", 0).await.unwrap(),
|
||||
vec!["jane@example.org".to_compact_string()]
|
||||
vec!["jane@example.org".to_string()]
|
||||
);
|
||||
assert_eq!(
|
||||
core.vrfy(&handle, "info", 0).await.unwrap(),
|
||||
Vec::<CompactString>::new()
|
||||
Vec::<String>::new()
|
||||
);
|
||||
assert_eq!(
|
||||
core.vrfy(&handle, "invalid", 0).await.unwrap(),
|
||||
Vec::<CompactString>::new()
|
||||
Vec::<String>::new()
|
||||
);
|
||||
|
||||
// EXPN (now handled by the internal store)
|
||||
|
||||
Reference in New Issue
Block a user