diff --git a/crates/brk_computer/src/storage/vecs/base.rs b/crates/brk_computer/src/storage/vecs/base.rs index 8ae0c1a28..c7f35c968 100644 --- a/crates/brk_computer/src/storage/vecs/base.rs +++ b/crates/brk_computer/src/storage/vecs/base.rs @@ -10,11 +10,10 @@ use std::{ use brk_core::CheckedSub; use brk_exit::Exit; use brk_vec::{ - AnyStorableVec, Compressed, Error, Result, StorableVec, StoredIndex, StoredType, Version, + AnyStorableVec, Compressed, Error, MAX_CACHE_SIZE, Result, StorableVec, StoredIndex, + StoredType, Version, }; -const FLUSH_EVERY: usize = 10_000; - #[derive(Debug)] pub struct ComputedVec { computed_version: Option, @@ -26,6 +25,8 @@ where I: StoredIndex, T: StoredType, { + const SIZE_OF: usize = size_of::(); + pub fn forced_import( path: &Path, version: Version, @@ -63,7 +64,7 @@ where } } - if self.vec.pushed_len() >= FLUSH_EVERY { + if self.vec.pushed_len() * Self::SIZE_OF >= MAX_CACHE_SIZE { Ok(self.safe_flush(exit)?) } else { Ok(()) diff --git a/crates/brk_vec/src/lib.rs b/crates/brk_vec/src/lib.rs index c0d90ee09..40ef32dee 100644 --- a/crates/brk_vec/src/lib.rs +++ b/crates/brk_vec/src/lib.rs @@ -427,7 +427,9 @@ where } }; - self.mut_file().write_all(&bytes)?; + let file = self.mut_file(); + file.write_all(&bytes)?; + file.sync_all()?; self.reset_caches();