readmodel

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: Apache-2.0 Imports: 26 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 readmodel keeps every unit's row derived, encoded and revised in memory, rebuilt from one store snapshot when a row input changes.

Index

Constants

View Source
const FacetWaitsOn = "waits-on"

FacetWaitsOn is the facet of whom a row waits on, by login or team.

Variables

This section is empty.

Functions

func BuildCatalog

func BuildCatalog(providers ...Provider) api.CatalogResponse

BuildCatalog is the served presentation of the providers that are Presenters, in their order; a view id another provider took first is left out, and a provider's view orders follow the previous providers'.

Types

type Agents

type Agents interface {
	Agents() (agents []turns.AgentObservation, ok bool)
}

Agents is the agents' last known states; ok is false when they are unknown.

type AgentsFunc

type AgentsFunc func() ([]turns.AgentObservation, bool)

AgentsFunc adapts a function to Agents.

func (AgentsFunc) Agents

func (f AgentsFunc) Agents() ([]turns.AgentObservation, bool)

type Base

type Base struct {
	Viewers map[unit.ProviderID]string
	Teams   []string // the github viewer's teams
	Specs   []api.ActionSpec
	// SpecsVersion is the version of GET /api/actions the rows' actions follow.
	SpecsVersion string
	// Intents are the loaded intents whose actions a row of a provider other than GitHub offers; nil offers
	// none.
	Intents *intentload.Loaded
	Pending map[unit.Unit]round.Pending
	Agents  []turns.AgentObservation
	// AgentsOK is false when the agents are unknown, so no session can be
	// told waiting.
	AgentsOK bool
	// Asked is the action a request asks for; zero for a served row.
	Asked catalog.Asked
}

Base is what every row of a rebuild shares, built once per rebuild.

type Books

type Books interface {
	Books(ctx context.Context, units ...unit.Unit) (map[unit.Unit]turn.Book, error)
}

Books reads turn books.

type Built

type Built struct {
	Entry
	Provider Provider
	In       any
}

Built is a served entry with what its row was derived from.

type Entry

type Entry struct {
	Unit unit.Unit
	Row  api.Row
	JSON []byte
	Rev  uint64
}

Entry is one unit's row as served: JSON is Row encoded, Rev the revision at which JSON last changed.

type Kept

type Kept struct {
	Base Base
	At   time.Time
	Rows []Built
}

Kept is a snapshot as its keeper sees it: the base, the minute and every row, shared with the snapshot and read-only.

type Model

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

Model serves every provider's rows from one immutable snapshot, rebuilt whole when a row input changed or the minute moved.

func New

func New(changes port.Changes, snap Snapshotter, pending Pending, agents Agents, settings Settings, providers ...Provider) *Model

New builds a model over the providers. A nil changes rebuilds on every read; nil pending, agents or settings leave their Base fields zero.

func (*Model) Base

func (m *Model) Base(ctx context.Context) (Base, time.Time, error)

Base is what the current snapshot's rows share, and the minute they were derived at.

func (*Model) Catalog

func (m *Model) Catalog() api.CatalogResponse

Catalog is the served presentation of the model's providers.

func (*Model) Check

func (m *Model) Check(ctx context.Context) []string

Check derives every row from scratch at the snapshot's minute and lists each unit whose served row differs, with the fields that differ; none when the snapshot matches or none was served yet.

func (*Model) Current

func (m *Model) Current(ctx context.Context) (Kept, error)

Current is the snapshot that holds every write noted before the call, as its keeper sees it. Its rows are shared: read them, never change them.

func (*Model) Labels

func (m *Model) Labels(units []unit.Unit) map[unit.Unit]string

Labels are the labels of units in the latest snapshot, such as "owner/repo#12" or "#channel"; a unit it does not list has none. It never rebuilds the rows.

func (*Model) Presentations

func (m *Model) Presentations(units []unit.Unit) map[unit.Unit]Presentation

Presentations are the presentations of the units the snapshot lists, without a sync.

func (*Model) Read

func (m *Model) Read(ctx context.Context, u unit.Unit) (Read, bool, error)

Read is u's entry; ok is false for a unit no provider lists. The row is a copy the caller may change; In is shared and must not be.

func (*Model) ReadMany

func (m *Model) ReadMany(ctx context.Context, units []unit.Unit) (map[unit.Unit]Read, Base, time.Time, error)

ReadMany is the entries of the units any provider lists, from one snapshot, with the base and the minute it holds.

func (*Model) Refresh

func (m *Model) Refresh(ctx context.Context) error

Refresh brings the snapshot up to date and runs the keeper on it if it is new, as Run does on each note and minute.

func (*Model) Row

func (m *Model) Row(ctx context.Context, u unit.Unit, asked catalog.Asked) (api.Row, bool, error)

Row is a copy of u's row, derived for a request that asks for an action; ok is false for a unit no provider lists.

func (*Model) Rows

func (m *Model) Rows(ctx context.Context, view string, since api.Since) (api.RowsPage, error)

Rows is the view's rows: all of them when since is zero, of another epoch, ahead of Rev or behind the tombstones, else those that changed after since and the units that left. The rows are copies the caller may change.

func (*Model) Run

func (m *Model) Run(ctx context.Context, publish func(api.Change))

Run keeps the snapshot current until ctx ends: it rebuilds on a row input's note, debounced, and on the minute, and publishes a Change each time the revision moved.

func (*Model) Served

func (m *Model) Served() bool

Served tells whether the model has built a snapshot yet.

func (*Model) Since

func (m *Model) Since(ctx context.Context, since api.Since) (api.Change, error)

Since is what a client at since missed: the units whose row changed or left after it, or All when since is of another epoch, ahead of Rev or behind the tombstones. A zero since missed nothing, so its Change only says where the rows are.

func (*Model) UseClock

func (m *Model) UseClock(now func() time.Time)

UseClock sets the clock rows are derived at.

func (*Model) UseKeeper

func (m *Model) UseKeeper(keep func(ctx context.Context, k Kept))

UseKeeper sets the bookkeeping Refresh does once per new snapshot, off the read path: the writes the rows imply.

func (*Model) UseLog

func (m *Model) UseLog(logf func(format string, args ...any))

UseLog sets where Run logs a failed rebuild.

type Pending

type Pending interface {
	Pending(ctx context.Context) (map[unit.Unit]round.Pending, error)
}

Pending is the set of pending automatic rounds.

type Presentation

type Presentation struct{ Label, Title, Link string }

Presentation is a unit's label, title and link as its row shows them.

type Presenter

type Presenter interface {
	Views() []api.ViewSpec
	Facets() []api.FacetSpec
	Situations() []api.SituationSpec
}

Presenter is optional on a Provider: its served views, facets and situations, read once per catalog build.

type Provider

type Provider interface {
	Provider() unit.ProviderID
	// Listed are the units the provider serves a row for.
	Listed(ctx context.Context) ([]unit.Unit, error)
	// Load reads what the rows of units derive from; a unit missing from
	// the result has no row.
	Load(ctx context.Context, units []unit.Unit) (map[unit.Unit]any, error)
	// Derive is pure: the row of one unit from base and what Load read,
	// with the Link and Label Load read; the model sets the row's Unit.
	Derive(base Base, in any, at time.Time) (api.Row, error)
}

Provider is one provider's rows.

type Read

type Read struct {
	Row  api.Row
	In   any
	Base Base
	At   time.Time
	// contains filtered or unexported fields
}

Read is one unit's entry of a snapshot: the served row, what it derives from and the base it was derived with.

func (Read) Derive

func (r Read) Derive(base Base, in any) (api.Row, error)

Derive is the unit's row from base and in, at the minute of the snapshot.

type RowDeps

type RowDeps struct {
	Books    Books
	Sessions Sessions
	// Intakes are the open intakes, the oldest first.
	Intakes func(ctx context.Context) ([]intake.Intake, error)
	// Intake is a row's view of an open intake, from its unit's brief record
	// (found false: none); attempt is the brief attempt the intake waits on.
	Intake   func(i intake.Intake, rec dinv.BriefRecord, found bool, attempt func() (int, error)) api.Intake
	Settings func() RowSettings
	Logf     func(format string, args ...any)
}

RowDeps are what the daemon supplies to any provider's rows. Books, Sessions, Intakes and Intake may be nil: no turns, no sessions, no intakes.

type RowSettings

type RowSettings struct {
	Cfg    config.Config
	Loaded *intentload.Loaded
	GateOn bool
	// Forceable is the last remove refusal of a unit that force gets past,
	// "" for none.
	Forceable func(unit.Unit) string
}

RowSettings is what every row reads of the configuration, the profile and the daemon, read once per load.

type Sessions

type Sessions interface {
	// Sessions lists the sessions not closed.
	Sessions(ctx context.Context) ([]turn.Session, error)
	Session(ctx context.Context, handle string) (turn.Session, bool, error)
}

Sessions reads the managed sessions.

type Settings

type Settings interface {
	Settings(ctx context.Context) (Base, error)
}

Settings supplies the Base fields no other port does: viewers, teams and action specs.

type Snapshotter

type Snapshotter interface {
	Snapshot(ctx context.Context, fn func(ctx context.Context) error) error
}

Snapshotter runs fn with every store read made with its ctx inside one read transaction.

type Summary

type Summary = api.Summary

Summary is what any provider's row says in generic terms.

Directories

Path Synopsis
Package cards keeps the units' card snapshots and derived items current with the rows the read model publishes.
Package cards keeps the units' card snapshots and derived items current with the rows the read model publishes.
Package prrow derives the row of a pull request from what the store, the gate and the turns say of it: the github provider of the read model.
Package prrow derives the row of a pull request from what the store, the gate and the turns say of it: the github provider of the read model.

Jump to

Keyboard shortcuts

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