pagination

package
v0.65.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 16, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package pagination holds cursor-pagination helpers shared by the metadata plugin backends (sqlite, postgres, mysql). It lives outside the metadata package itself because that package blank-imports the backends for plugin registration; a backend importing metadata back would cycle.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtendPageToFullTxGroup

func ExtendPageToFullTxGroup[T BlockTxPositioned](
	db *gorm.DB,
	rows []T,
	limit int,
) ([]T, error)

ExtendPageToFullTxGroup re-queries db for every row sharing the last row's (block_number, tx_index) key and appends any rows from that group not already present in rows.

(block_number, tx_index) is not a unique key in the midnight_* tables: a single transaction can write more than one row to the same table (for example several cNIGHT outputs created in one tx). If a page's SQL LIMIT lands in the middle of such a group, a cursor that resumes strictly after (block_number, tx_index) would silently skip the remaining rows in that group forever. Extending the page to the end of the group closes that gap, at the cost of an occasional page slightly larger than the requested limit.

rows must already be ordered ascending by (block_number, tx_index) and contain exactly limit rows (the function is a no-op otherwise, since a short page cannot have been cut mid-group). db must carry no lingering WHERE/ORDER conditions from the caller's own query — GORM chain calls clone rather than mutate, so reusing the handle that ran that query is safe.

The replacement group is ordered by id ASC, so repeated calls for the same page return the tied rows in the same order — every current caller's row model has an auto-increment "id" primary key column.

Types

type BlockTxPositioned

type BlockTxPositioned interface {
	BlockTxPosition() (blockNumber uint64, txIndex uint32)
}

BlockTxPositioned is implemented by row models that carry a (block_number, tx_index) cursor position, e.g. the midnight_* UTxO-event tables.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL