MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / new

Method new

atomic-repository/examples/materialize_bench.rs:174–306  ·  view source on GitHub ↗
(parent: &Path, config: &Config, span: bool)

Source from the content-addressed store, hash-verified

172
173impl Fixture {
174 fn new(parent: &Path, config: &Config, span: bool) -> Result<Self> {
175 let started = Instant::now();
176 let directory = tempfile::Builder::new()
177 .prefix(if span { "span-" } else { "graph-" })
178 .tempdir_in(parent)?;
179 let root = directory.path();
180 let mut repo = Repository::init(root)?;
181 if span {
182 let mut txn = repo.pristine().write_txn()?;
183 txn.put_required_capability(SPAN_RANGE_CAPABILITY)?;
184 txn.commit()?;
185 }
186 fs::create_dir(root.join("files"))?;
187 let mut contents: Vec<Vec<String>> = (0..config.files)
188 .map(|file| {
189 (0..config.lines)
190 .map(|line| format!("file_{file:04} line_{line:06} value_00000000\n"))
191 .collect()
192 })
193 .collect();
194 for (file, lines) in contents.iter().enumerate() {
195 fs::write(
196 root.join(format!("files/file_{file:04}.txt")),
197 lines.concat(),
198 )?;
199 }
200 fs::write(root.join("empty.txt"), [])?;
201 let wc = repo.require_working_copy_id()?;
202 repo.add(wc, "files", Default::default())?;
203 repo.add(wc, "empty.txt", Default::default())?;
204 let mut tick = 0;
205 record(&repo, "synthetic baseline", &mut tick)?;
206 for edit in 0..config.edits {
207 let line = (edit * 17) % config.lines;
208 contents[0][line] = format!("file_0000 line_{line:06} value_{:08}\n", edit + 1);
209 fs::write(root.join("files/file_0000.txt"), contents[0].concat())?;
210 record(&repo, "synthetic hot-file edit", &mut tick)?;
211 }
212 let mut golden = BTreeMap::new();
213 let capture = |content: &[Vec<String>]| -> Result<Vec<Golden>> {
214 let mut files = Vec::new();
215 for (file, lines) in content.iter().enumerate() {
216 let path = format!("files/file_{file:04}.txt");
217 files.push(Golden {
218 mode: file_mode(&root.join(&path))?,
219 path,
220 content: lines.concat().into_bytes(),
221 });
222 }
223 files.push(Golden {
224 path: "empty.txt".into(),
225 content: Vec::new(),
226 mode: file_mode(&root.join("empty.txt"))?,
227 });
228 Ok(files)
229 };
230 golden.insert("dev".into(), capture(&contents)?);
231 repo.create_view_from("bench-near", "dev")?;

Callers

nothing calls this directly

Calls 15

fixture_file_indexFunction · 0.85
write_txnMethod · 0.80
pristineMethod · 0.80
concatMethod · 0.80
create_view_fromMethod · 0.80
iter_mutMethod · 0.80
recordFunction · 0.70
file_modeFunction · 0.70
initFunction · 0.50

Tested by

no test coverage detected