Skip to content

Commit

Permalink
Store OpHeadsStore in UnpublishedOperation instead of RepoLoader
Browse files Browse the repository at this point in the history
The only thing we need from the `RepoLoader` is the `OpHeadsStore`, so we can
extract it in UnpublishedOperation::new instead of keeping the entire
`RepoLoader` around.
  • Loading branch information
emesterhazy committed Mar 2, 2024
1 parent f5a3366 commit b6439c9
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use itertools::Itertools as _;

use crate::backend::Timestamp;
use crate::index::ReadonlyIndex;
use crate::op_heads_store::OpHeadsStore;
use crate::op_store::OperationMetadata;
use crate::operation::Operation;
use crate::repo::{MutableRepo, ReadonlyRepo, Repo, RepoLoader, RepoLoaderError};
Expand Down Expand Up @@ -155,7 +156,7 @@ pub fn create_op_metadata(
/// finish the operation.
#[must_use = "Either publish() or leave_unpublished() must be called to finish the operation."]
pub struct UnpublishedOperation {
repo_loader: RepoLoader,
op_heads_store: Arc<dyn OpHeadsStore>,
repo: Arc<ReadonlyRepo>,
}

Expand All @@ -166,18 +167,19 @@ impl UnpublishedOperation {
view: View,
index: Box<dyn ReadonlyIndex>,
) -> Self {
let repo = repo_loader.create_from(operation, view, index);
UnpublishedOperation { repo_loader, repo }
UnpublishedOperation {
op_heads_store: repo_loader.op_heads_store().clone(),
repo: repo_loader.create_from(operation, view, index),
}
}

pub fn operation(&self) -> &Operation {
self.repo.operation()
}

pub fn publish(self) -> Arc<ReadonlyRepo> {
let _lock = self.repo_loader.op_heads_store().lock();
self.repo_loader
.op_heads_store()
let _lock = self.op_heads_store.lock();
self.op_heads_store
.update_op_heads(self.operation().parent_ids(), self.operation().id());
self.repo
}
Expand Down

0 comments on commit b6439c9

Please sign in to comment.