compress cache key

This commit is contained in:
Conrad Ludgate
2024-06-28 09:12:18 +01:00
parent 108f08f982
commit 4c78a5067f
2 changed files with 8 additions and 12 deletions

View File

@@ -157,12 +157,10 @@ smol_str_wrapper!(BranchId);
// 90% of project strings are 23 characters or less.
smol_str_wrapper!(ProjectId);
// ket value neon_option fields
smol_str_wrapper!(EndpointCacheKeyExtra);
#[derive(PartialEq, Eq, Hash, Debug, Clone)]
pub struct EndpointCacheKey {
pub id: EndpointIdInt,
pub extra: EndpointCacheKeyExtra,
pub extra: Box<str>,
}
impl std::fmt::Display for EndpointCacheKey {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {

View File

@@ -11,7 +11,6 @@ pub use copy_bidirectional::copy_bidirectional_client_compute;
pub use copy_bidirectional::ErrorSource;
use crate::intern::EndpointIdInt;
use crate::EndpointCacheKeyExtra;
use crate::{
auth,
cancellation::{self, CancellationHandlerMain, CancellationHandlerMainInternal},
@@ -413,14 +412,13 @@ impl NeonOptions {
}
}
pub fn get_cache_key_extras(&self) -> EndpointCacheKeyExtra {
// prefix + format!(" {k}:{v}")
// kinda jank because SmolStr is immutable
self.0
.iter()
.flat_map(|(k, v)| [" ", &**k, ":", &**v])
.collect::<SmolStr>()
.into()
pub fn get_cache_key_extras(&self) -> Box<str> {
let mut extras = String::new();
for (k, v) in &self.0 {
use std::fmt::Write;
write!(&mut extras, " {k}:{v}").unwrap();
}
extras.into_boxed_str()
}
/// <https://swagger.io/docs/specification/serialization/> DeepObject format