Skip to content

Conversation

@Evalir
Copy link
Member

@Evalir Evalir commented Oct 23, 2025

Adds cursor-based pagination types to the tx-cache crate. This allows us to implement pagination on the cache, and for the tx-cache client to be able to use pagination queries.

Getting all items in one of the collections in the cache is as simple as:

  • getting items in the collection, which will return a PaginationInfo
  • passing the cursor returned from PaginationInfo into the next request. This can easily be done by .into()ing a PaginationInfo into a PaginationParams.
  • do this repeatedly until there are no more pages. PaginationInfo has an utility method to detect this.

These changes are not breaking for the current tx cache consumers.

Copy link
Member Author

Evalir commented Oct 23, 2025

This stack of pull requests is managed by Graphite. Learn more about stacking.

@Evalir Evalir force-pushed the evalir/cache-pagination branch 2 times, most recently from 695f90e to 38133ea Compare October 23, 2025 15:52
@Evalir Evalir force-pushed the evalir/cache-pagination branch from 38133ea to 9c99eeb Compare October 23, 2025 16:32
@Evalir Evalir marked this pull request as ready for review October 23, 2025 16:34
@Evalir Evalir requested a review from a team as a code owner October 23, 2025 16:34
Copy link
Member

is this a breaking change for existing consumers of the api? i.e. if they are using an older version of the builder will their builder break if I deploy this version of the tx cache?

@Evalir
Copy link
Member Author

Evalir commented Oct 27, 2025

Not technically a breaking change. The builder will still be able to fetch items from the cache as serde can partially deserialize JSON (it's a self-described format). They will be missing the pagination info, which is fine for now. I've added partial deser tests on the companion pagination PR to confirm this.

@prestwich
Copy link
Member

prestwich commented Oct 30, 2025

these changes are currently breaking, as serde will expect pagination info to be present unless given a specific serde(default) or similar attribute tag

@prestwich
Copy link
Member

I would prefer to see something like:

pub enum CacheResponse<T> { 
    Paginated{
        inner: T,
        pagination: PaginationInfo
    },
    Unpaginated(T),
}

@Evalir
Copy link
Member Author

Evalir commented Oct 31, 2025

took a stab at the suggestion @prestwich, wdyt?

Copy link
Member

@prestwich prestwich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add serde roundtrip tests with what you think these json objects should look like.

If pagination params is a query, I don't think it's appropriate to use serde. Instead, there should be a method to apply it to a url?

/// The cursor to start from.
cursor: Option<String>,
/// The number of items to return.
limit: Option<u32>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing serde tags for if missing or none

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing serde renames

/// Represents the pagination information from a transaction cache response.
/// This applies to all GET endpoints that return a list of items.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PaginationInfo {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing serde for missing/none on next_cursor

/// Represents the pagination information from a transaction cache response.
/// This applies to all GET endpoints that return a list of items.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PaginationInfo {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing serde renames

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't has_next_page redundant? shouldn't we use presence/absence of a next_cursor to indicate this?


impl From<PaginationInfo> for PaginationParams {
fn from(info: PaginationInfo) -> Self {
Self { cursor: info.into_next_cursor(), limit: None }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this feels like an inappropriate from impl. Maybe a next_page(&self, page_size: Option<usize>) function instead?


/// A response from the transaction cache, containing an item.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum CacheResponse<T> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing serde tags

@@ -1,18 +1,21 @@
//! The endpoints for the transaction cache.
use std::collections::HashMap;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit remove newline

}

async fn get_inner_with_query<T>(
async fn get_inner_with_query<C: CursorKey, T>(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you make a trait for the output you can remove the C here and avoid specifying it in turbofish elsewhere

trait CacheObject {
    type Key: CursorKey;
}


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants