backfillutil

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatCursor

func FormatCursor(idx int) networkid.PaginationCursor

func IndexAtOrAfter

func IndexAtOrAfter(n int, getTime func(i int) time.Time, anchor time.Time) int

IndexAtOrAfter returns the first index i in [0, n) where getTime(i) >= anchor, using binary search. Returns 0 if anchor is zero.

func NextStreamOrder

func NextStreamOrder(last int64, ts time.Time) int64

NextStreamOrder computes a monotonically increasing stream order value derived from a timestamp. If the timestamp-based order would not exceed last, it returns last+1 to guarantee strict ordering.

func ParseCursor

func ParseCursor(cursor networkid.PaginationCursor) (int, bool)

Types

type PaginateParams

type PaginateParams struct {
	Count              int
	Forward            bool
	Cursor             networkid.PaginationCursor
	AnchorMessage      *database.Message
	ForwardAnchorShift int // added to anchor index in forward mode (e.g. 1 to start after anchor)
}

PaginateParams controls how a slice of backfill entries is paginated. Cursor is only used for backward pagination (Forward == false).

type PaginateResult

type PaginateResult struct {
	Start, End int
	Cursor     networkid.PaginationCursor
	HasMore    bool
}

PaginateResult describes the selected window within the full entry slice.

func Paginate

func Paginate(
	totalLen int,
	params PaginateParams,
	findAnchor func(*database.Message) (int, bool),
	indexAtOrAfter func(*database.Message) int,
) PaginateResult

Paginate selects a window of entries from a sorted slice using cursor/anchor-based pagination.

findAnchor returns the index of the anchor message within the entries (and true), or false if not found. indexAtOrAfter returns the first index whose timestamp is >= the anchor time.

Jump to

Keyboard shortcuts

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