Skip to content

Commit 32d2316

Browse files
committed
refactor out method to add to tx cache
1 parent 1a680b0 commit 32d2316

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/new_index/schema.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -877,13 +877,19 @@ impl ChainQuery {
877877
self.store.txstore_db.get(&TxRow::key(&txid[..]))
878878
};
879879
if let Some(result) = result.as_ref() {
880-
if let Ok(mut cache) = self.txs_cache.lock() {
881-
let _ = cache.insert(txid.clone(), result);
882-
}
880+
self.add_txs_to_cache(&[(*txid, result)]);
883881
}
884882
result
885883
}
886884

885+
pub fn add_txs_to_cache<T: AsRef<[u8]>>(&self, txs: &[(Txid, T)]) {
886+
if let Ok(mut cache) = self.txs_cache.lock() {
887+
for (txid, tx) in txs {
888+
let _ = cache.insert(*txid, &tx.as_ref());
889+
}
890+
}
891+
}
892+
887893
pub fn lookup_txo(&self, outpoint: &OutPoint) -> Option<TxOut> {
888894
let _timer = self.start_timer("lookup_txo");
889895
lookup_txo(&self.store.txstore_db, outpoint)

0 commit comments

Comments
 (0)