Repository navigation
chore(store): generalize pagination for the store - #2737
SantiagoPittella wants to merge 8 commits into
Conversation
|
The |
| after: Option<&AccountId>, | ||
| ) -> Result<Page<(AccountId, Word), AccountId>, DatabaseError> { | ||
| // Fetch one extra to determine if there are more results | ||
| let limit = i64::try_from(self.page_size.get() + 1).expect("page size fits within i64"); | ||
|
|
||
| let commitments = match after { | ||
| Some(cursor) => { | ||
| tx.query(SQL_AFTER_CURSOR, &[&limit, &VALID_FOREVER, cursor], commitment_from_row)? | ||
| }, | ||
| None => tx.query(SQL_FIRST_PAGE, &[&limit, &VALID_FOREVER], commitment_from_row)?, | ||
| }; |
There was a problem hiding this comment.
I wonder if perhaps we shouldn't use next: &AccountId instead of after: Option<T>? In general for all the pagination; this would remove a layer of mapping/indirection I think.
There was a problem hiding this comment.
It might then also make sense to have Cursor::default so that can do .map(..).unwrap_or_default().
Though that might not fit the current shape very well.
There was a problem hiding this comment.
I changed to something similar. For the account ids and nullifier queries the cursor is Option<AccountId/Nullifier> and None means to start from the first row. An empty blob sorts before every key, so I reintroduced the account_id >= ? statements that we were using before, and the match and the second SQL file are gone (we were using one SQL file for first page, another for the others).
closes #2730
Adds a
Paginatedtrait to the store and moves all paginated reads onto it. Queries return a sharedPage { items, next}.Db::pagereads one page andDb::pagesstreams all of them, replacing hand-written loops. Each query had its own page type and progress reporting. One contract keeps them consistent and makes paginating inside a stream trivial for future streaming endpoints.Also:
OUT_OF_RANGEwhen one block exceeds the page limit, instead of an empty page that skipped it.block_numis the last fully covered block, so it can be further ahead than the last row.SyncNotesreturnsblock_towhen done.protois unchanged.Changelog