diff --git a/crates/table/src/blob_store.rs b/crates/table/src/blob_store.rs index 6155d884b5d..2f3b286ab44 100644 --- a/crates/table/src/blob_store.rs +++ b/crates/table/src/blob_store.rs @@ -12,6 +12,7 @@ //! It is not optimize and is mainly intended for testing purposes. use blake3::hash; +use core::mem; use spacetimedb_data_structures::map::{hash_map::Entry, HashMap}; use spacetimedb_lib::{de::Deserialize, ser::Serialize}; use spacetimedb_memory_usage::MemoryUsage; @@ -233,15 +234,20 @@ impl BlobStore for HashMapBlobStore { } } -#[cfg(test)] impl HashMapBlobStore { - /// Returns an iterator over the (hash, usage count, blob bytes) triple. - fn iter(&self) -> impl Iterator + '_ { - self.map.iter().map(|(hash, obj)| (hash, obj.uses, &*obj.blob)) + /// Merge `src_bs` into `self`. + pub fn merge_from(&mut self, src_bs: Self) { + for (hash, mut obj) in src_bs.map { + let uses = mem::take(&mut obj.uses); + self.map.entry(hash).or_insert(obj).uses += uses; + } } +} +#[cfg(test)] +impl HashMapBlobStore { /// Returns a map relating blob hashes to the usage count in this blob store. pub fn usage_counter(&self) -> HashMap { - self.iter().map(|(hash, uses, _)| (*hash, uses)).collect() + self.iter_blobs().map(|(hash, uses, _)| (*hash, uses)).collect() } }