Skip to content

Commit

Permalink
fix: avoid reuse of derivation index update logic
Browse files Browse the repository at this point in the history
  • Loading branch information
hydra-yse committed Dec 15, 2024
1 parent a428d36 commit 6346ab1
Showing 1 changed file with 11 additions and 20 deletions.
31 changes: 11 additions & 20 deletions lib/core/src/persist/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,21 +111,23 @@ impl Persister {
self.get_cached_item(KEY_WEBHOOK_URL)
}

pub fn set_last_derivation_index(&self, index: u32) -> Result<()> {
let mut con = self.get_connection()?;
let tx = con.transaction_with_behavior(TransactionBehavior::Immediate)?;

Self::update_cached_item_inner(&tx, KEY_LAST_DERIVATION_INDEX, index.to_string())?;
pub fn set_last_derivation_index_inner(&self, tx: &Transaction, index: u32) -> Result<()> {
Self::update_cached_item_inner(tx, KEY_LAST_DERIVATION_INDEX, index.to_string())?;
self.commit_outgoing(
&tx,
tx,
LAST_DERIVATION_INDEX_DATA_ID,
RecordType::LastDerivationIndex,
// insert a mock updated field so that merging with incoming data works as expected
Some(vec![LAST_DERIVATION_INDEX_DATA_ID.to_string()]),
)?;
)
}

pub fn set_last_derivation_index(&self, index: u32) -> Result<()> {
let mut con = self.get_connection()?;
let tx = con.transaction_with_behavior(TransactionBehavior::Immediate)?;
self.set_last_derivation_index_inner(&tx, index)?;
tx.commit()?;
self.sync_trigger.try_send(())?;

Ok(())
}

Expand All @@ -143,18 +145,7 @@ impl Persister {
.as_str()
.parse::<u32>()
.map(|index| index + 1)?;
Self::update_cached_item_inner(
&tx,
KEY_LAST_DERIVATION_INDEX,
next_index.to_string(),
)?;
self.commit_outgoing(
&tx,
LAST_DERIVATION_INDEX_DATA_ID,
RecordType::LastDerivationIndex,
// insert a mock updated field so that merging with incoming data works as expected
Some(vec![LAST_DERIVATION_INDEX_DATA_ID.to_string()]),
)?;
self.set_last_derivation_index_inner(&tx, next_index)?;
Some(next_index)
}
None => None,
Expand Down

0 comments on commit 6346ab1

Please sign in to comment.