| 351 | } |
| 352 | |
| 353 | pub async fn insert_graph( |
| 354 | &self, |
| 355 | writeable_folder: ValidWriteableGraphFolder, |
| 356 | graph: MaterializedGraph, |
| 357 | ) -> Result<(), InsertionError> { |
| 358 | let key = writeable_folder.local_path().to_owned(); |
| 359 | let config = self.graph_conf.clone(); |
| 360 | self.cache |
| 361 | .insert_or_replace_with(&key, |old_graph| async { |
| 362 | invalidate_graph(old_graph).await; |
| 363 | blocking_compute(move || { |
| 364 | let (is_dirty, new_graph) = writeable_folder.write_graph_data(graph, config)?; |
| 365 | let folder = writeable_folder.finish()?; |
| 366 | let graph = GraphWithVectors::new(new_graph, None, folder.as_existing()?); |
| 367 | graph.set_dirty(is_dirty); |
| 368 | Ok::<_, InsertionError>(graph) |
| 369 | }) |
| 370 | .await |
| 371 | }) |
| 372 | .await?; |
| 373 | Ok(()) |
| 374 | } |
| 375 | |
| 376 | /// Insert a graph serialized from a graph folder. |
| 377 | pub async fn insert_graph_as_bytes<R: Read + Seek + Send + 'static>( |