From 4c5695f0cd1fe198450fe4b0800ebe0088b7aca8 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Sun, 26 Feb 2023 12:03:07 -0800 Subject: [PATCH] index_store: take OperationId when writing new index By taking an `OperationId` argument to `IndexStore::write_index()`, we can remove `associate_file_with_operation()` from the trait. That simplifies the interace a little bit. The reason I noticed this was that I'm trying to extract a trait for `IndexStore`, and the word "file" in it is too specific for e.g. a cloud-based implementation. --- lib/src/index_store.rs | 12 +++++++++--- lib/src/transaction.rs | 5 ++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/src/index_store.rs b/lib/src/index_store.rs index 97c4b50c5..e4311c0f2 100644 --- a/lib/src/index_store.rs +++ b/lib/src/index_store.rs @@ -75,8 +75,14 @@ impl IndexStore { } } - pub fn write_index(&self, index: MutableIndex) -> io::Result> { - index.save_in(self.dir.clone()) + pub fn write_index( + &self, + index: MutableIndex, + op_id: &OperationId, + ) -> io::Result> { + let index = index.save_in(self.dir.clone())?; + self.associate_file_with_operation(&index, op_id)?; + Ok(index) } fn load_index_at_operation( @@ -161,7 +167,7 @@ impl IndexStore { } /// Records a link from the given operation to the this index version. - pub fn associate_file_with_operation( + fn associate_file_with_operation( &self, index: &ReadonlyIndex, op_id: &OperationId, diff --git a/lib/src/transaction.rs b/lib/src/transaction.rs index 7f2002ab9..afff05994 100644 --- a/lib/src/transaction.rs +++ b/lib/src/transaction.rs @@ -97,7 +97,6 @@ impl Transaction { ); let base_repo = mut_repo.base_repo().clone(); let (mut_index, view) = mut_repo.consume(); - let index = base_repo.index_store().write_index(mut_index).unwrap(); let view_id = base_repo.op_store().write_view(view.store_view()).unwrap(); self.op_metadata.end_time = self.end_time.unwrap_or_else(Timestamp::now); @@ -113,9 +112,9 @@ impl Transaction { .unwrap(); let operation = Operation::new(base_repo.op_store().clone(), new_op_id, store_operation); - base_repo + let index = base_repo .index_store() - .associate_file_with_operation(&index, operation.id()) + .write_index(mut_index, operation.id()) .unwrap(); UnpublishedOperation::new(base_repo.loader(), operation, view, index) }