view

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: MIT Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package view keeps live, ordered message lists for clients (the view domain in docs/specs/rpc-api.md).

Index

Constants

View Source
const Debounce = 50 * time.Millisecond

Debounce is how long the manager waits after a change before recomputing views, so a burst of commits (an initial sync) costs one recompute.

Variables

View Source
var ErrNotFound = errors.New("view: not found")

ErrNotFound means the view does not exist or belongs to another connection.

Functions

func Diff

func Diff(old, new []int64) []api.ViewOp

Diff turns an old view into the ops that produce new. IDs are unique within each list. The rows that stay put are a longest strictly increasing subsequence of the new indexes of the shared IDs, so a small edit stays a small delta. Removes come first, from the end of old toward the start, so earlier indexes stay valid; then inserts, from the start of new toward the end, where each run lands exactly at its new index. Diff returns nil when nothing changed.

Types

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager keeps the open views. Each is an ordered ID snapshot owned by one connection; after relevant commits the manager recomputes it and sends the owner a view.delta.

func NewManager

func NewManager(db *store.DB, log *slog.Logger) *Manager

NewManager returns a Manager; Run must be running for views to update.

func (*Manager) Close

func (m *Manager) Close(conn api.Conn, id int64) error

Close closes a view conn owns.

func (*Manager) Filter added in v0.10.0

func (m *Manager) Filter(conn api.Conn, id int64) (store.ViewFilter, error)

Filter returns the stored filter of a view conn owns.

func (*Manager) OnCommit

func (m *Manager) OnCommit(evs []api.EventEnvelope)

OnCommit marks views affected by committed events dirty; it is chained into the store's OnCommit hook and never blocks.

func (*Manager) Open

func (m *Manager) Open(ctx context.Context, conn api.Conn, f store.ViewFilter) (int64, int, error)

Open snapshots f for conn and closes the view when conn ends.

func (*Manager) Range

func (m *Manager) Range(conn api.Conn, id int64, start, end int) ([]int64, error)

Range returns the IDs in [start, end) of a view conn owns; end is capped at the view's length.

func (*Manager) Run

func (m *Manager) Run(ctx context.Context)

Run recomputes dirty views until ctx ends.

Jump to

Keyboard shortcuts

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