Skip to content
This repository was archived by the owner on Apr 9, 2024. It is now read-only.

perf: support pagination in get_live_cells_by_item #351

Merged
merged 2 commits into from
Dec 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,26 @@ impl PaginationRequest {
}
}

pub fn set_order(mut self, order: Order) -> Self {
pub fn order(mut self, order: Order) -> Self {
self.set_order(order);
self
}

pub fn set_order(&mut self, order: Order) {
self.order = order;
}

pub fn limit(mut self, limit: Option<u64>) -> Self {
self.set_limit(limit);
self
}

pub fn set_limit(mut self, limit: Option<u64>) -> Self {
pub fn set_limit(&mut self, limit: Option<u64>) {
self.limit = limit;
self
}

pub fn update_by_response<T>(&mut self, response: PaginationResponse<T>) {
self.cursor = response.next_cursor;
}
}

Expand All @@ -227,6 +239,22 @@ pub struct PaginationResponse<T> {
pub count: Option<u64>,
}

impl<T> PaginationResponse<T> {
pub fn new(response: Vec<T>) -> Self {
Self {
response,
next_cursor: None,
count: None,
}
}
}

impl<T> Default for PaginationResponse<T> {
fn default() -> Self {
Self::new(vec![])
}
}

#[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct DetailedCell {
pub epoch_number: u64,
Expand Down
7 changes: 7 additions & 0 deletions core/cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ pub struct MercuryConfig {

#[serde(default = "default_extensions_config")]
pub extensions_config: Vec<ExtensionConfig>,

#[serde(default = "default_pool_cache_size")]
pub pool_cache_size: u64,
}

impl MercuryConfig {
Expand Down Expand Up @@ -205,6 +208,10 @@ fn default_extensions_config() -> Vec<ExtensionConfig> {
vec![]
}

fn default_pool_cache_size() -> u64 {
100u64
}

fn default_file_size_limit() -> u64 {
1073741824 // 1GiB
}
Expand Down
1 change: 1 addition & 0 deletions core/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ impl<'a> Cli<'a> {
self.parse_cmd_args("ckb_uri", self.config.network_config.ckb_uri.clone()),
self.config.cheque_since,
LevelFilter::from_str(&self.config.db_config.db_log_level).unwrap(),
self.config.pool_cache_size,
);

let stop_handle = service
Expand Down
3 changes: 3 additions & 0 deletions core/rpc/core/src/impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ pub struct MercuryRpcImpl<C> {
cheque_timeout: RationalU256,
cellbase_maturity: RationalU256,
sync_state: Arc<RwLock<SyncState>>,
pool_cache_size: u64,
}

#[async_trait]
Expand Down Expand Up @@ -277,6 +278,7 @@ impl<C: CkbRpc> MercuryRpcImpl<C> {
cheque_timeout: RationalU256,
cellbase_maturity: RationalU256,
sync_state: Arc<RwLock<SyncState>>,
pool_cache_size: u64,
) -> Self {
SECP256K1_CODE_HASH.swap(Arc::new(
builtin_scripts
Expand Down Expand Up @@ -332,6 +334,7 @@ impl<C: CkbRpc> MercuryRpcImpl<C> {
cheque_timeout,
cellbase_maturity,
sync_state,
pool_cache_size,
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion core/rpc/core/src/impl/adjust_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ use core_rpc_types::{

use common::hash::blake2b_256_to_160;
use common::utils::decode_udt_amount;
use common::{Address, AddressPayload, Context, DetailedCell, ACP, SECP256K1, SUDT};
use common::{
Address, AddressPayload, Context, DetailedCell, PaginationRequest, ACP, SECP256K1, SUDT,
};
use common_logger::tracing_async;

use ckb_types::core::TransactionView;
Expand Down Expand Up @@ -48,6 +50,7 @@ impl<C: CkbRpc> MercuryRpcImpl<C> {
Some((**ACP_CODE_HASH.load()).clone()),
None,
false,
&mut PaginationRequest::default(),
)
.await?;
let live_acps_len = live_acps.len();
Expand Down
Loading