diff --git a/Cargo.toml b/Cargo.toml index 0b843a40f2..9941b21f3b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -49,10 +49,10 @@ bytes = { version = "1.5.0", optional = true } percent-encoding = { version = "2.3.0", optional = true } mini-moka = { version = "0.10.2", optional = true } mime_guess = { version = "2.0.4", optional = true } -dashmap = { version = "5.5.3", features = ["serde"], optional = true } +dashmap = { version = "6.1.0", features = ["serde"], optional = true } parking_lot = { version = "0.12.1"} ed25519-dalek = { version = "2.0.0", optional = true } -typesize = { version = "0.1.6", optional = true, features = ["url", "time", "serde_json", "secrecy", "dashmap", "parking_lot", "nonmax", "extract_map_01", "details"] } +typesize = { version = "0.1.6", optional = true, features = ["url", "time", "serde_json", "secrecy", "parking_lot", "nonmax", "extract_map_01"] } # serde feature only allows for serialisation, # Serenity workspace crates serenity-voice-model = { version = "0.2.0", path = "./voice-model", optional = true } @@ -115,7 +115,7 @@ full = ["default", "collector", "voice", "voice_model", "interactions_endpoint"] # Enables temporary caching in functions that retrieve data via the HTTP API. temp_cache = ["cache", "mini-moka", "typesize?/mini_moka"] -typesize = ["dep:typesize", "small-fixed-array/typesize", "bool_to_bitflags/typesize"] +typesize = ["dep:typesize", "dashmap/typesize", "small-fixed-array/typesize", "bool_to_bitflags/typesize"] # Enables compile-time heavy instrument macros from tracing tracing_instrument = ["tracing/attributes"] diff --git a/src/cache/mod.rs b/src/cache/mod.rs index cbff4c9445..5ab26c8580 100644 --- a/src/cache/mod.rs +++ b/src/cache/mod.rs @@ -56,8 +56,8 @@ struct NotSend; enum CacheRefInner<'a, K, V, T> { #[cfg(feature = "temp_cache")] Arc(Arc), - DashRef(Ref<'a, K, V, BuildHasher>), - DashMappedRef(MappedRef<'a, K, T, V, BuildHasher>), + DashRef(Ref<'a, K, V>), + DashMappedRef(MappedRef<'a, K, T, V>), ReadGuard(parking_lot::RwLockReadGuard<'a, V>), } @@ -79,11 +79,11 @@ impl<'a, K, V, T> CacheRef<'a, K, V, T> { Self::new(CacheRefInner::Arc(inner.get_inner())) } - fn from_ref(inner: Ref<'a, K, V, BuildHasher>) -> Self { + fn from_ref(inner: Ref<'a, K, V>) -> Self { Self::new(CacheRefInner::DashRef(inner)) } - fn from_mapped_ref(inner: MappedRef<'a, K, T, V, BuildHasher>) -> Self { + fn from_mapped_ref(inner: MappedRef<'a, K, T, V>) -> Self { Self::new(CacheRefInner::DashMappedRef(inner)) } diff --git a/src/cache/wrappers.rs b/src/cache/wrappers.rs index e4d8d6ce60..49ad508747 100644 --- a/src/cache/wrappers.rs +++ b/src/cache/wrappers.rs @@ -14,15 +14,15 @@ use typesize::TypeSize; /// A wrapper around Option> to ease disabling specific cache fields. pub(crate) struct MaybeMap(pub(super) Option>); impl MaybeMap { - pub fn iter(&self) -> impl Iterator> { + pub fn iter(&self) -> impl Iterator> { Option::iter(&self.0).flat_map(DashMap::iter) } - pub fn get(&self, k: &K) -> Option> { + pub fn get(&self, k: &K) -> Option> { self.0.as_ref()?.get(k) } - pub fn get_mut(&self, k: &K) -> Option> { + pub fn get_mut(&self, k: &K) -> Option> { self.0.as_ref()?.get_mut(k) } @@ -59,8 +59,10 @@ impl TypeSize for MaybeMap { self.0.as_ref().map(DashMap::extra_size).unwrap_or_default() } - fn get_collection_item_count(&self) -> Option { - self.0.as_ref().and_then(DashMap::get_collection_item_count) + typesize::if_typesize_details! { + fn get_collection_item_count(&self) -> Option { + self.0.as_ref().and_then(DashMap::get_collection_item_count) + } } } @@ -69,11 +71,11 @@ impl TypeSize for MaybeMap { /// map without allowing mutation of internal cache fields, which could cause issues. pub struct ReadOnlyMapRef<'a, K: Eq + Hash, V>(Option<&'a DashMap>); impl<'a, K: Eq + Hash, V> ReadOnlyMapRef<'a, K, V> { - pub fn iter(&self) -> impl Iterator> { + pub fn iter(&self) -> impl Iterator> { self.0.into_iter().flat_map(DashMap::iter) } - pub fn get(&self, k: &K) -> Option> { + pub fn get(&self, k: &K) -> Option> { self.0?.get(k) } @@ -91,6 +93,10 @@ impl std::hash::Hasher for Hasher { self.0.write(bytes); } } + +#[cfg(feature = "typesize")] +impl typesize::TypeSize for Hasher {} + #[derive(Clone, Default)] pub struct BuildHasher(fxhash::FxBuildHasher); impl std::hash::BuildHasher for BuildHasher { @@ -101,6 +107,9 @@ impl std::hash::BuildHasher for BuildHasher { } } +#[cfg(feature = "typesize")] +impl typesize::TypeSize for BuildHasher {} + /// Wrapper around `SizableArc`` with support for disabling typesize. /// /// This denotes an Arc where T's size should be considered when calling `TypeSize::get_size`