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.
This commit is contained in:
Martin von Zweigbergk 2023-02-26 12:03:07 -08:00 committed by Martin von Zweigbergk
parent 346e3c849b
commit 4c5695f0cd
2 changed files with 11 additions and 6 deletions

View file

@ -75,8 +75,14 @@ impl IndexStore {
}
}
pub fn write_index(&self, index: MutableIndex) -> io::Result<Arc<ReadonlyIndex>> {
index.save_in(self.dir.clone())
pub fn write_index(
&self,
index: MutableIndex,
op_id: &OperationId,
) -> io::Result<Arc<ReadonlyIndex>> {
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,

View file

@ -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)
}