Skip to content

Commit

Permalink
address remaining comments
Browse files Browse the repository at this point in the history
  • Loading branch information
wlmyng committed Aug 19, 2024
1 parent 1e334a9 commit 322f0c6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
8 changes: 4 additions & 4 deletions crates/sui-graphql-rpc/src/types/transaction_block/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ fn apply_forward_scan_limited_pagination(
conn.start_cursor = Some(
Cursor::new(cursor::TransactionBlockCursor {
checkpoint_viewed_at,
tx_sequence_number: tx_bounds.inclusive_lo(),
tx_sequence_number: tx_bounds.inclusive_scan_lo(),
is_scan_limited: true,
})
.encode_cursor(),
Expand All @@ -550,7 +550,7 @@ fn apply_forward_scan_limited_pagination(
conn.end_cursor = Some(
Cursor::new(cursor::TransactionBlockCursor {
checkpoint_viewed_at,
tx_sequence_number: tx_bounds.inclusive_hi(),
tx_sequence_number: tx_bounds.inclusive_scan_hi(),
is_scan_limited: true,
})
.encode_cursor(),
Expand All @@ -572,7 +572,7 @@ fn apply_backward_scan_limited_pagination(
conn.end_cursor = Some(
Cursor::new(cursor::TransactionBlockCursor {
checkpoint_viewed_at,
tx_sequence_number: tx_bounds.inclusive_hi(),
tx_sequence_number: tx_bounds.inclusive_scan_hi(),
is_scan_limited: true,
})
.encode_cursor(),
Expand All @@ -586,7 +586,7 @@ fn apply_backward_scan_limited_pagination(
conn.start_cursor = Some(
Cursor::new(cursor::TransactionBlockCursor {
checkpoint_viewed_at,
tx_sequence_number: tx_bounds.inclusive_lo(),
tx_sequence_number: tx_bounds.inclusive_scan_lo(),
is_scan_limited: true,
})
.encode_cursor(),
Expand Down
22 changes: 16 additions & 6 deletions crates/sui-graphql-rpc/src/types/transaction_block/tx_lookups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ impl TxBounds {
max_option([self.after, Some(self.lo)]).unwrap()
}

/// Determines the lower bound for the scanning range. `exclude_cursor` determines whether to
/// include `after` cursor in this calculation. When paginating backwards, the lower bound is
/// the larger of either the lower bound or the `tx_sequence_number` some `scan_limit` distance
/// less than the upper bound. The latter is additionally added by 1 if `before` cursor is None
/// to avoid over-counting.
fn calculate_lo(&self, exclude_cursor: bool) -> u64 {
let cursor_lo = self.cursor_lo().saturating_add(exclude_cursor as u64);

Expand All @@ -166,12 +171,12 @@ impl TxBounds {
/// the lower bound is the larger between the former and the `tx_sequence_number` some
/// `scan_limit` distance less than the upper bound.
pub(crate) fn scan_lo(&self) -> u64 {
self.calculate_lo(false)
self.calculate_lo(/* exclude_cursor */ false)
}

/// The lower bound `tx_sequence_number` of the scanned transactions, exclusive of the `after`
/// cursor.
pub(crate) fn inclusive_lo(&self) -> u64 {
pub(crate) fn inclusive_scan_lo(&self) -> u64 {
self.calculate_lo(self.after.is_some())
}

Expand All @@ -180,6 +185,11 @@ impl TxBounds {
min_option([self.before, Some(self.hi)]).unwrap()
}

/// Determines the upper bound for the scanning range. `exclude_cursor` determines whether to
/// include `before` cursor in this calculation. When paginating forwards, the upper bound is
/// the smaller of either the upper bound or the `tx_sequence_number` some `scan_limit` distance
/// more than the lower bound. The latter is additionally subtracted by 1 if `after` cursor is
/// None to avoid over-counting.
fn calculate_hi(&self, exclude_cursor: bool) -> u64 {
let cursor_hi = self.cursor_hi().saturating_sub(exclude_cursor as u64);

Expand All @@ -205,23 +215,23 @@ impl TxBounds {
/// then the upper bound is the smaller between the former and the `tx_sequence_number` some
/// `scan_limit` distance more than the lower bound.
pub(crate) fn scan_hi(&self) -> u64 {
self.calculate_hi(false)
self.calculate_hi(/* exclude_cursor */ false)
}

/// The upper bound `tx_sequence_number` of the scanned transactions, exclusive of the `before`
/// cursor.
pub(crate) fn inclusive_hi(&self) -> u64 {
pub(crate) fn inclusive_scan_hi(&self) -> u64 {
self.calculate_hi(self.before.is_some())
}

/// Whether there are more transactions to scan to the left of this page.
pub(crate) fn scan_has_prev_page(&self) -> bool {
self.lo < self.inclusive_lo()
self.lo < self.inclusive_scan_lo()
}

/// Whether there are more transactions to scan to the right of this page.
pub(crate) fn scan_has_next_page(&self) -> bool {
self.inclusive_hi() < self.hi
self.inclusive_scan_hi() < self.hi
}
}

Expand Down

0 comments on commit 322f0c6

Please sign in to comment.