From 4c78a5067f0818bc1f816f715faaa41497586df1 Mon Sep 17 00:00:00 2001 From: Conrad Ludgate Date: Fri, 28 Jun 2024 09:12:18 +0100 Subject: [PATCH] compress cache key --- proxy/src/lib.rs | 4 +--- proxy/src/proxy.rs | 16 +++++++--------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/proxy/src/lib.rs b/proxy/src/lib.rs index 78f0c350a9..e304cfa2b9 100644 --- a/proxy/src/lib.rs +++ b/proxy/src/lib.rs @@ -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, } impl std::fmt::Display for EndpointCacheKey { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { diff --git a/proxy/src/proxy.rs b/proxy/src/proxy.rs index 84a0aae652..76f84975ad 100644 --- a/proxy/src/proxy.rs +++ b/proxy/src/proxy.rs @@ -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::() - .into() + pub fn get_cache_key_extras(&self) -> Box { + 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() } /// DeepObject format