store

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: Apache-2.0 Imports: 15 Imported by: 1 module, 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 store is the GitHub plugin's own database, in the state directory the host gives it: the pull requests it reads, their sightings and details, the workspaces' fetches, its meta values and the overrides it keeps of what the user set.

Index

Constants

View Source
const DetailVersion = 2

DetailVersion is the shape of Detail this release reads; a stored detail of another version is read again by the next fast run.

View Source
const TimeLayout = "2006-01-02T15:04:05.000000000Z"

TimeLayout is how the store writes a time, the host's layout, so an imported time reads and its text sorts as the store's own.

View Source
const ViewerKey = "viewer:" + "github"

ViewerKey is the meta key of the viewer's login, as the host's store kept it before the plugin had a store.

Variables

This section is empty.

Functions

func FactsOf

func FactsOf(p pr.PR, d Detail, viewer string) pr.Facts

FactsOf is p with its detail d as the rules read them, the viewer's own reviews marked and every login bare.

Types

type Change

type Change struct {
	Refs []pr.Ref
}

Change is what one write transaction changed: the pull requests whose reported facts it moved.

type DB

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

DB is the plugin's store. Every write runs under one lock, and each commit that changed pull requests is heard by the OnChange listeners, in commit order.

func Open

func Open(ctx context.Context, dir string) (*DB, error)

Open opens dir's store, creating it with the plugin's schema, and imports the import.db the host's store migration exported once.

func (*DB) Adopted

func (db *DB) Adopted(ctx context.Context) (map[pr.Ref]bool, error)

Adopted are the pull requests taken over into the loop.

func (*DB) Close

func (db *DB) Close() error

func (*DB) DetailStamps

func (db *DB) DetailStamps(ctx context.Context, refs []pr.Ref) (map[pr.Ref]Detail, error)

DetailStamps are the version and read time of each ref's stored detail, without its body.

func (*DB) Details

func (db *DB) Details(ctx context.Context, refs []pr.Ref) (map[pr.Ref]Detail, error)

Details returns the stored detail of each ref that has one, one query per 500 refs.

func (*DB) HostEvents

func (db *DB) HostEvents(ctx context.Context, refs []pr.Ref, since time.Time, kinds ...string) ([]pr.Event, error)

HostEvents reads the host's events of refs of kinds, every kind when empty, at or after since, oldest first.

func (*DB) LastEvent

func (db *DB) LastEvent(ctx context.Context, ref pr.Ref, kind string) (pr.Event, bool, error)

LastEvent is the newest event of kind on ref.

func (*DB) LastFetch

func (db *DB) LastFetch(ctx context.Context, id string) (time.Time, error)

LastFetch is the last fetch of workspace id, zero when it was never fetched.

func (*DB) ListPRs

func (db *DB) ListPRs(ctx context.Context, open bool) ([]pr.PR, error)

ListPRs reads every stored pull request, or the open ones, the most recently updated first.

func (*DB) MarkFetch

func (db *DB) MarkFetch(ctx context.Context, id string, at time.Time) error

MarkFetch records a fetch of workspace id at at, which changes no reported fact.

func (*DB) Meta

func (db *DB) Meta(ctx context.Context, key string) (string, error)

Meta is key's value, "" when unset. Meta values change no reported fact.

func (*DB) MetaPrefixed

func (db *DB) MetaPrefixed(ctx context.Context, prefix string) (map[string]string, error)

MetaPrefixed is every meta value whose key starts with prefix, by key.

func (*DB) OnChange

func (db *DB) OnChange(f func(Change))

OnChange makes f hear every later commit that changed pull requests.

func (*DB) Override

func (db *DB) Override(ctx context.Context, ref pr.Ref) (pr.Override, error)

Override is what the user set on ref; the zero override when none.

func (*DB) PR

func (db *DB) PR(ctx context.Context, ref pr.Ref) (pr.PR, bool, error)

PR is the stored pull request ref; false when the store lacks it.

func (*DB) PRs

func (db *DB) PRs(ctx context.Context, refs []pr.Ref) (map[pr.Ref]pr.PR, error)

PRs reads the stored pull requests among refs, leaving out those it lacks.

func (*DB) RecordEvents

func (db *DB) RecordEvents(ctx context.Context, evs []pr.Event) error

RecordEvents records evs on the host. A keyed event is kept once per pull request, kind and key.

func (*DB) ReplaceWorkspaces

func (db *DB) ReplaceWorkspaces(ctx context.Context, links map[pr.Ref]pr.Workspace) error

ReplaceWorkspaces makes links the set of linked pull requests in one transaction, so readers never see the links blank. It writes only the links that differ from the stored ones, recording on the host first the followed or unfollowed events of the scope flips.

func (*DB) Retain

func (db *DB) Retain(ctx context.Context, endedBefore, fetchesBefore time.Time) ([]pr.Ref, error)

Retain drops what the host's retention ends: every row of a pull request merged or closed before endedBefore, and the fetches before fetchesBefore, in one transaction. It returns the pull requests it dropped, which no later report names.

func (*DB) SaveDetail

func (db *DB) SaveDetail(ctx context.Context, ref pr.Ref, d Detail) error

SaveDetail stores d as ref's detail unless it equals the stored one.

func (*DB) SaveSnapshots

func (db *DB) SaveSnapshots(ctx context.Context, snaps []Snapshot, seenAt time.Time) (map[pr.Ref]int, error)

SaveSnapshots stores snaps. The events, host data, go to the host first: the timeline events the host does not hold yet, the merges that fill a stored one, and a followed or unfollowed event for each pull request whose scope flips, derived from a read of the stored rows. Then one write transaction rewrites a row only when a column differs, records every ref as seen, and writes a detail only when it differs from the stored one. A write that fails after the host took the events leaves the rows as they were, so the next save derives the same events again and the host keeps each once. seenAt dates the sighting, a new conflict, the flips and a detail without ReadAt. It returns the events added per ref that gained any.

func (*DB) SeeRefs

func (db *DB) SeeRefs(ctx context.Context, refs []pr.Ref, at time.Time) error

SeeRefs records that a search or a read returned refs at at. A sighting changes no reported fact.

func (*DB) Seen

func (db *DB) Seen(ctx context.Context) (map[pr.Ref]time.Time, error)

Seen is when a search or a read last returned each open pull request.

func (*DB) SetAdopted

func (db *DB) SetAdopted(ctx context.Context, ref pr.Ref) error

SetAdopted marks ref taken over, writing that column alone.

func (*DB) SetMeta

func (db *DB) SetMeta(ctx context.Context, key, value string) error

func (*DB) SetMetas

func (db *DB) SetMetas(ctx context.Context, kv map[string]string) error

SetMetas writes every key of kv in one transaction.

func (*DB) SetReasons

func (db *DB) SetReasons(ctx context.Context, ref pr.Ref, reasons []string) error

SetReasons replaces ref's follow reasons, keeping ReasonTracked while its override tracks it, and recording on the host first the followed or unfollowed event of a scope flip.

func (*DB) SetTracked

func (db *DB) SetTracked(ctx context.Context, ref pr.Ref, tracked bool) (changed bool, err error)

SetTracked tracks or untracks ref, keeping its reasons in step and recording on the host first the followed or unfollowed event of a scope flip; changed says the override moved.

func (*DB) SetViewer

func (db *DB) SetViewer(ctx context.Context, login string) error

func (*DB) SetWorkspace

func (db *DB) SetWorkspace(ctx context.Context, ref pr.Ref, ws pr.Workspace) error

SetWorkspace links ref to ws, recording on the host first the followed or unfollowed event of a scope flip.

func (*DB) StoredFacts

func (db *DB) StoredFacts(ctx context.Context, refs []pr.Ref) (map[pr.Ref]StoredFacts, error)

StoredFacts reads the facts of refs: the stored pull requests, then their pushes and unfilled merges from the host's events.

func (*DB) TouchStubs

func (db *DB) TouchStubs(ctx context.Context, stubs []Stub, seenAt time.Time) error

TouchStubs refreshes the review requests, the review decision, the sighting and the mergeable state of pull requests a search returned unchanged, in one transaction. A closed pull request's mergeable state is not followed.

func (*DB) Track

func (db *DB) Track(ctx context.Context, ref pr.Ref, tracked bool, at time.Time, data string) (changed bool, err error)

Track tracks or untracks ref, recording the tracked or untracked event of the move on the host, at at with data, before its write, as a scope flip is: a move the host refused leaves the row as it was, and a retry after a write that failed finds the host's last event of the kind it records and records none. Changed says the override moved.

func (*DB) Tracked

func (db *DB) Tracked(ctx context.Context) ([]pr.Ref, error)

Tracked lists the pull requests the user tracks, in ref order.

func (*DB) UpsertPR

func (db *DB) UpsertPR(ctx context.Context, p pr.PR) error

UpsertPR stores p as SaveSnapshots does, seen at its LastSeenAt.

func (*DB) UseClock

func (db *DB) UseClock(now func() time.Time)

UseClock makes now the time of a scope flip no write dates.

func (*DB) UseHost

func (db *DB) UseHost(h Host)

UseHost makes h the host the store records its events to and reads them from; a store with no host refuses every write that derives an event.

func (*DB) Viewer

func (db *DB) Viewer(ctx context.Context) (string, error)

Viewer is the stored viewer login, "" before it is known.

func (*DB) Write

func (db *DB) Write(ctx context.Context, fn func(tx *Tx) error) (Change, error)

Write runs fn in one write transaction. After the commit, the listeners hear what fn touched; an error from fn rolls back and tells nobody.

type Detail

type Detail struct {
	Version                 int       `json:"-"`
	ReadAt                  time.Time `json:"-"`
	AuthorAssociation       string
	Visibility              string // the repository's: public, private or internal
	Labels                  []string
	Commits                 []pr.Commit // the newest 50, oldest first
	Reviews                 []pr.Review // the newest 100, oldest first; HasContent set, ByViewer unset
	LatestReviews           []pr.Review // latestReviews(first: 20)
	NewestChangesRequestOid string
	Comments                []pr.Comment // the newest 100, oldest first
	Checks                  []pr.Check   // the head's contexts, first 50
	ThreadsTotal            int
	// OpenThreads holds the unresolved threads among the newest 50 when
	// ThreadsRead: read for a pull request with ThreadsTotal > 0 the viewer
	// authored or develops in a workspace, and known empty when ThreadsTotal
	// is 0.
	OpenThreads []pr.Thread
	ThreadsRead bool
}

Detail is what deciding on a pull request reads beyond its row: the collector's full read, stored as GitHub returned it.

func (Detail) Fresh

func (d Detail) Fresh(now time.Time, maxAge time.Duration) bool

Fresh tells a detail of this release's version read within maxAge of now.

type Host

type Host interface {
	RecordEvents(ctx context.Context, events []src.Event) error
	Events(ctx context.Context, q src.EventQuery) ([]src.Event, error)
}

Host is where the events of the store's pull requests live: the host's event log, written and read through the broker.

type Snapshot

type Snapshot struct {
	PR     pr.PR      // Reasons are merged with the stored ones; LastSeenAt and Workspace are ignored
	Events []pr.Event // the timeline; those the host holds already are ignored
	Merges []pr.Event // merged events that fill a stored one lacking the merger or the commit
	Detail *Detail    // nil keeps the stored one
}

Snapshot is one pull request as GitHub returned it, ready to store.

type StoredFacts

type StoredFacts struct {
	PR             pr.PR // zero when not Found
	Found          bool
	Pushes         map[string]time.Time // push key -> at
	UnfilledMerges []time.Time          // merged events lacking the merger or the commit
}

StoredFacts is what storing a fresh GitHub snapshot needs of the stored one.

type Stub

type Stub struct {
	Ref            pr.Ref
	State          string
	Mergeable      string
	ReviewRequests []string
	ReviewDecision string
}

Stub is what a search returns of a pull request beyond its version: the facts the store refreshes without a full read.

type Tx

type Tx struct {
	*sql.Tx
	// contains filtered or unexported fields
}

Tx is a write transaction that records the pull requests it changed.

func (*Tx) Touch

func (tx *Tx) Touch(refs ...pr.Ref)

Touch records that the transaction changed the reported facts of refs.

Jump to

Keyboard shortcuts

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