Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
fominok committed Oct 29, 2024
1 parent bdef719 commit 15b3034
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 15 deletions.
2 changes: 1 addition & 1 deletion grovedb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@ impl GroveDb {
.follow_reference(
(full_path.as_slice()).into(),
allow_cache,
Some(transaction),
transaction,
grove_version,
)
.unwrap()?;
Expand Down
11 changes: 6 additions & 5 deletions grovedb/src/operations/get/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,15 @@ impl GroveDb {
);

let mut cost = OperationCost::default();
let tx = TxRef::new(&self.db, transaction);

match cost_return_on_error!(
&mut cost,
self.get_raw_caching_optional(
path.clone(),
key,
allow_cache,
transaction,
Some(tx.as_ref()),
grove_version
)
) {
Expand All @@ -87,7 +88,7 @@ impl GroveDb {
self.follow_reference(
path_owned.as_slice().into(),
allow_cache,
transaction,
tx.as_ref(),
grove_version,
)
.add_cost(cost)
Expand All @@ -99,11 +100,11 @@ impl GroveDb {
/// Return the Element that a reference points to.
/// If the reference points to another reference, keep following until
/// base element is reached.
pub fn follow_reference<B: AsRef<[u8]>>(
pub(crate) fn follow_reference<B: AsRef<[u8]>>(
&self,
path: SubtreePath<B>,
allow_cache: bool,
transaction: TransactionArg,
transaction: &Transaction,
grove_version: &GroveVersion,
) -> CostResult<Element, Error> {
check_grovedb_v0_with_cost!(
Expand Down Expand Up @@ -134,7 +135,7 @@ impl GroveDb {
path_slice.into(),
key,
allow_cache,
transaction,
Some(transaction),
grove_version
)
.map_err(|e| match e {
Expand Down
19 changes: 12 additions & 7 deletions grovedb/src/operations/get/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use integer_encoding::VarInt;
use crate::element::SumValue;
use crate::{
element::QueryOptions, operations::proof::ProveOptions,
query_result_type::PathKeyOptionalElementTrio,
query_result_type::PathKeyOptionalElementTrio, util::TxRef, Transaction,
};
#[cfg(feature = "full")]
use crate::{
Expand Down Expand Up @@ -56,6 +56,7 @@ impl GroveDb {
);

let mut cost = OperationCost::default();
let tx = TxRef::new(&self.db, transaction);

let elements = cost_return_on_error!(
&mut cost,
Expand Down Expand Up @@ -83,7 +84,7 @@ impl GroveDb {
.follow_reference(
absolute_path.as_slice().into(),
allow_cache,
transaction,
tx.as_ref(),
grove_version,
)
.unwrap_add_cost(&mut cost)?;
Expand Down Expand Up @@ -182,7 +183,7 @@ where {
element: Element,
allow_cache: bool,
cost: &mut OperationCost,
transaction: TransactionArg,
transaction: &Transaction,
grove_version: &GroveVersion,
) -> Result<Element, Error> {
check_grovedb_v0!(
Expand Down Expand Up @@ -248,6 +249,7 @@ where {
grove_version.grovedb_versions.operations.query.query
);
let mut cost = OperationCost::default();
let tx = TxRef::new(&self.db, transaction);

let (elements, skipped) = cost_return_on_error!(
&mut cost,
Expand All @@ -266,7 +268,7 @@ where {
.into_iterator()
.map(|result_item| {
result_item.map_element(|element| {
self.follow_element(element, allow_cache, &mut cost, transaction, grove_version)
self.follow_element(element, allow_cache, &mut cost, tx.as_ref(), grove_version)
})
})
.collect::<Result<Vec<QueryResultElement>, Error>>();
Expand Down Expand Up @@ -295,6 +297,7 @@ where {
.query_item_value
);
let mut cost = OperationCost::default();
let tx = TxRef::new(&self.db, transaction);

let (elements, skipped) = cost_return_on_error!(
&mut cost,
Expand Down Expand Up @@ -327,7 +330,7 @@ where {
.follow_reference(
absolute_path.as_slice().into(),
allow_cache,
transaction,
tx.as_ref(),
grove_version,
)
.unwrap_add_cost(&mut cost)?;
Expand Down Expand Up @@ -387,6 +390,7 @@ where {
.query_item_value_or_sum
);
let mut cost = OperationCost::default();
let tx = TxRef::new(&self.db, transaction);

let (elements, skipped) = cost_return_on_error!(
&mut cost,
Expand Down Expand Up @@ -419,7 +423,7 @@ where {
.follow_reference(
absolute_path.as_slice().into(),
allow_cache,
transaction,
tx.as_ref(),
grove_version,
)
.unwrap_add_cost(&mut cost)?;
Expand Down Expand Up @@ -485,6 +489,7 @@ where {
grove_version.grovedb_versions.operations.query.query_sums
);
let mut cost = OperationCost::default();
let tx = TxRef::new(&self.db, transaction);

let (elements, skipped) = cost_return_on_error!(
&mut cost,
Expand Down Expand Up @@ -517,7 +522,7 @@ where {
.follow_reference(
absolute_path.as_slice().into(),
allow_cache,
transaction,
tx.as_ref(),
grove_version,
)
.unwrap_add_cost(&mut cost)?;
Expand Down
2 changes: 1 addition & 1 deletion grovedb/src/operations/insert/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ impl GroveDb {
self.follow_reference(
reference_path.as_slice().into(),
false,
Some(transaction),
transaction,
grove_version
)
);
Expand Down
2 changes: 1 addition & 1 deletion grovedb/src/operations/proof/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ impl GroveDb {
self.follow_reference(
absolute_path.as_slice().into(),
true,
None,
tx,
grove_version
)
);
Expand Down

0 comments on commit 15b3034

Please sign in to comment.