-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
perf: Add support for multi get operation for database queries #2396
base: master
Are you sure you want to change the base?
Changes from 24 commits
c77045f
e66db04
9eace87
8ba0c9d
76b919b
2333dfb
49994b9
2fb9e88
b2c2632
df63d48
4d5ca7d
36a50bb
6275b36
e1e50fa
f76d210
4feadfd
e141f56
8e3fd0f
39664bb
52eca64
5b0e975
bc955fd
491c452
676a5d4
8b35460
f697707
3d0a71f
5de80b7
d7a30c8
f27bdbb
9ea8894
2c2d222
df33ef2
79e42da
cbb6efc
07f9b94
75fedc7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -177,7 +177,7 @@ impl LowerHex for TxPointer { | |
} | ||
} | ||
|
||
#[derive(cynic::Scalar, Debug, Clone)] | ||
#[derive(cynic::Scalar, Debug, Clone, PartialEq, Eq)] | ||
pub struct HexString(pub Bytes); | ||
|
||
impl From<HexString> for Vec<u8> { | ||
|
@@ -194,7 +194,7 @@ impl Deref for HexString { | |
} | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
#[derive(Debug, Clone, PartialEq, Eq)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. |
||
pub struct Bytes(pub Vec<u8>); | ||
|
||
impl FromStr for Bytes { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,8 +12,6 @@ use fuel_core_storage::{ | |
IntoBoxedIter, | ||
IterDirection, | ||
}, | ||
not_found, | ||
tables::Transactions, | ||
transactional::AtomicView, | ||
Error as StorageError, | ||
IsNotFound, | ||
|
@@ -65,6 +63,7 @@ use fuel_core_types::{ | |
use futures::Stream; | ||
use std::{ | ||
borrow::Cow, | ||
collections::BTreeMap, | ||
sync::Arc, | ||
}; | ||
|
||
|
@@ -141,29 +140,42 @@ impl ReadView { | |
pub fn transaction(&self, tx_id: &TxId) -> StorageResult<Transaction> { | ||
let result = self.on_chain.transaction(tx_id); | ||
if result.is_not_found() { | ||
if let Some(tx) = self.off_chain.old_transaction(tx_id)? { | ||
Ok(tx) | ||
} else { | ||
Err(not_found!(Transactions)) | ||
} | ||
self.off_chain.old_transaction(tx_id) | ||
} else { | ||
result | ||
} | ||
} | ||
|
||
pub async fn transactions( | ||
&self, | ||
tx_ids: Vec<TxId>, | ||
) -> Vec<StorageResult<Transaction>> { | ||
// TODO: Use multiget when it's implemented. | ||
// https://github.com/FuelLabs/fuel-core/issues/2344 | ||
let result = tx_ids | ||
pub async fn transactions(&self, tx_ids: &[TxId]) -> Vec<StorageResult<Transaction>> { | ||
let on_chain_results: BTreeMap<_, _> = tx_ids | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is nice that this function handles this hard use case. In most cases, we have only Can we first request values from the on-chain database, and if any of them are not found, we will fall back into the logic with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea, I'll do it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in 5de80b7 let me know what you think. |
||
.iter() | ||
.enumerate() | ||
.zip(self.on_chain.transactions(tx_ids.iter().into_boxed())) | ||
.collect(); | ||
|
||
let off_chain_indexed_txids: Vec<_> = on_chain_results | ||
.iter() | ||
.map(|tx_id| self.transaction(tx_id)) | ||
.collect::<Vec<_>>(); | ||
// Give a chance to other tasks to run. | ||
.filter_map(|(indexed_tx_id, result)| { | ||
result.is_not_found().then_some(*indexed_tx_id) | ||
}) | ||
.collect(); | ||
|
||
let off_chain_results = off_chain_indexed_txids.iter().copied().zip( | ||
self.off_chain.old_transactions( | ||
off_chain_indexed_txids | ||
.iter() | ||
.map(|(_, tx_id)| *tx_id) | ||
.into_boxed(), | ||
), | ||
); | ||
|
||
let mut results = on_chain_results; | ||
results.extend(off_chain_results); | ||
|
||
// Give a chance for other tasks to run. | ||
tokio::task::yield_now().await; | ||
result | ||
|
||
results.into_values().collect() | ||
} | ||
|
||
pub fn block(&self, height: &BlockHeight) -> StorageResult<CompressedBlock> { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these changes needed? I can't seem to find a place where these additional derives are necessary.