paged

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package paged reads linked sources in place: Parquet files and SQLite tables or queries too big for any grid, linked as tables on tabs of their own (the engine's source.go). Its Host answers what a workbook's formulas and pivot tables ask of them (sheet.SourceHost) by streaming the sources in the background, keeping the answers until a source's file changes; its Pages are the rows a source's tab shows, read a page at a time as it scrolls.

The Host and Pages belong to the goroutine that owns the workbook (the UI's). What reads files runs as Jobs on other goroutines, over what the Job took with it, and hands its result back to be stored, so the owner never waits on a file.

Index

Constants

View Source
const (
	PageRows = 128
)

PageRows is how many rows a page holds; keepPages is how many are kept.

Variables

This section is empty.

Functions

func Apply

func Apply(w *sheet.Workbook, d Done)

Apply tells the workbook what storing a job found: a source opened, or questions answered.

func ShapeOf

func ShapeOf(h fileio.Source) sheet.SourceShape

ShapeOf is what the engine keeps of a source.

Types

type Done

type Done struct {
	// Keys are the questions answered.
	Keys []string
	// Opened names a source opened, or failing to, with its shape.
	Opened string
	Shape  sheet.SourceShape
	Err    string
}

Done is what storing a job's result tells the workbook.

type Host

type Host struct {
	// Budget is how many cells a function that holds what it reads may
	// read of a source, and a range read whole may have: max-cells.
	Budget int
	// Open opens a source; fileio.OpenSource unless replaced.
	Open Opener
	// Debounce is how long a changed file must hold still before it's
	// read again.
	Debounce time.Duration
	// Now is the clock; tests replace it.
	Now func() time.Time
	// contains filtered or unexported fields
}

Host answers a workbook's questions about its linked sources.

func NewHost

func NewHost(budget int) *Host

NewHost is a host with budget max-cells.

func (*Host) Answer

func (h *Host) Answer(q sheet.SourceQuestion) (sheet.SourceAnswer, bool)

Answer returns the answer to q, or false while it isn't known, queuing q to be worked out (sheet.SourceHost).

func (*Host) Close

func (h *Host) Close()

Close lets every source go.

func (*Host) Jobs

func (h *Host) Jobs() []*Job

Jobs hands out the jobs queued since the last call, to run in the background, each once.

func (h *Host) Link(list []Linked) bool

Link makes the host's sources the workbook's: new ones and those reading something else are opened, those gone are closed. It returns whether anything changed.

func (*Host) Pending

func (h *Host) Pending() bool

Pending reports whether jobs are queued or running.

func (*Host) Poll

func (h *Host) Poll() bool

Poll looks at each source's file, once they're open, and queues the ones that changed and have held still for Debounce to be read again, reporting whether it queued any. A file that goes away is noticed the same way.

func (*Host) Reload

func (h *Host) Reload(name string)

Reload reads the source named name again, as when its file changed: what was worked out of it is worked out again.

func (*Host) Settle

func (h *Host) Settle(ctx context.Context, w *sheet.Workbook, links []Linked)

Settle links the sources links names (Links), unless links is nil, and runs every job the host queues, one after another, applying each, until none is left: for what has no screen to keep live while they run (012 get, tests).

func (*Host) Shape

func (h *Host) Shape(name string) (sheet.SourceShape, string, bool)

Shape is what the host found of the source named name: its shape, or why it can't be read, and whether it has been opened.

func (*Host) Source

func (h *Host) Source(name string) (fileio.Source, int, bool)

Source is the opened source named name, for its tab's pages.

func (*Host) Store

func (h *Host) Store(j *Job) Done

Store keeps what the job j found, run and back on the owner's goroutine, and says what the workbook is to be told.

type Job

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

A Job is work the host queued: opening a source, or answering a question by reading the sources it names. Run it on any goroutine, once, then give it back to Host.Store on the owner's.

func (*Job) Run

func (j *Job) Run(ctx context.Context)

Run does the job.

func (*Job) String

func (j *Job) String() string

String says what the job does, for telemetry.

type Linked

type Linked struct {
	Name string
	Spec fileio.SourceSpec
}

Linked is a source as the workbook links it, its file resolved.

func Links(w *sheet.Workbook, abs func(string) string, tempDir string) []Linked

Links are the workbook's linked sources as the host reads them: each one's file through abs (which resolves it from the workbook's folder), what they build kept in tempDir ("" for the system's).

type Opener

type Opener func(ctx context.Context, spec fileio.SourceSpec) (fileio.Source, error)

Opener opens what a spec names: fileio.OpenSource, or a stand-in.

type PageJob

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

PageJob builds a view or reads a page of it, on any goroutine.

func (*PageJob) Run

func (j *PageJob) Run(ctx context.Context)

Run does the job.

type Pages

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

Pages are the rows a source's tab shows, in its view's order (a sort and a filter, pushed down to SQL or streamed: fileio.SourceView), read a page at a time as the tab scrolls, and at most keepPages of them kept, so memory stays bounded whatever the source's size. Building a sorted or filtered view reads the whole source once; until it's built, and while a page is on its way, the rows it would show aren't known.

func NewPages

func NewPages(h fileio.Source, gen int, o *sheet.SourceOrder) *Pages

NewPages are the pages of the view of h, the gen'th opening of its source, ordered as o says.

func (*Pages) Building

func (p *Pages) Building() bool

Building reports whether the view is being built; Err says why it couldn't be.

func (*Pages) Close

func (p *Pages) Close()

Close lets go of the view.

func (*Pages) Err

func (p *Pages) Err() string

func (*Pages) Jobs

func (p *Pages) Jobs() []*PageJob

Jobs hands out the reads asked for since the last call, to run in the background.

func (*Pages) Of

func (p *Pages) Of(h fileio.Source, gen int) bool

Of reports whether the pages are of h's gen'th opening, however ordered.

func (*Pages) Row

func (p *Pages) Row(i int64) (int64, []sheet.LiveCell, bool)

Row is the view's row i: its number in the source and its values, with false while its page isn't read, which Want asks for.

func (*Pages) Rows

func (p *Pages) Rows() (int64, bool)

Rows counts the rows the view shows, with false while it's built.

func (*Pages) Same

func (p *Pages) Same(h fileio.Source, gen int, o *sheet.SourceOrder) bool

Same reports whether the pages are of h's gen'th opening, ordered as o says.

func (*Pages) Store

func (p *Pages) Store(j *PageJob) bool

Store keeps what a job read, back on the owner's goroutine, and reports whether it changed what shows.

func (*Pages) Want

func (p *Pages) Want(from, to int64)

Want asks for the pages holding rows from through to of the view, to be read unless they are.

Jump to

Keyboard shortcuts

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