STAGE TWO OF TWO. Stage 1 (aa10a725e) added MaxRows and SkipCounts to
ListRequest and flipped no routes; this is the flip, plus the one role the
decoration needed.
TWO PARTS, and the role first because the flip needs it.
THE ROLE. `issueops.BlockingAnnotator` answers the decoration a listing prints
beside each row — `(parent: X, blocked by: Y, blocks: Z)` — for the ids of a
page that has already been chosen. It is its own role rather than EdgeReader
growth (Q12 asked and answered two), and the distance between them is larger
than it looks: EdgeReader returns STORED ROWS of every type with targets
spelled as stored, no status consulted, and a per-anchor Missing flag from an
existence probe; this one returns a DERIVED summary of two types with closed
blockers dropped, the inbound direction included, and NO existence probe at
all. It is not Reader growth either — it has no order of its own, nothing it
returns depends on how the page was chosen, and a ListRequest field would have
implied the annotation was part of the query.
THERE IS NO MISSING FLAG, and that is a decision the leaf states rather than an
omission: an id that names nothing and an id with no live blocking edges
decorate identically, so a probe would be a read whose answer no caller can
use. One conformance case asserts that ABSENCE of a distinction.
A BLOCKER THIS DATABASE HOLDS NO ROW FOR COUNTS AS OPEN — an `external:`
reference, a foreign-repository id, a row whose issue was deleted. An
unreadable status is not `closed`, and a listing that hid a blocker it could
not resolve would report work as unblocked on the strength of a row it never
found. Both implementations already did this; it now has a sentence and a case.
THE ORDER WITHIN EACH LIST IS NOW PINNED, ascending with repeats collapsed, and
this is the commit's ONE user-visible change. Both lists are joined into one
line of output, so the query's natural order was user-visible bytes that could
move between runs. It affects only rows with two or more live blockers, and it
is recorded as A-blk-2.
TWO BODIES, NOT THREE. dolt and embeddeddolt share
storage/issueops.ExecuteBlockingAnnotation inside their own read transaction;
the unit-of-work provider is the genuinely separate one — it reads BOTH
dependency tiers for every id and merges, where the store side partitions the
ids by plane, and it resolves statuses only for the ids a row mentioned.
FinishBlockingAnnotation is what makes the SHAPE of the answer one decision
rather than two. Seventeen cases, three wirings, ZERO PARKS.
THE HTTP HALF. GET /v0/beads/dependencies/blocking, spec first, `make api-gen`
after. `IssueBlocking` is x-go-type-pinned to the role package the way `Cycle`
and `CycleMember` are, and BOTH the schema and the envelope's Items are pinned
in internal/httpapi/pinning.go — the v2.6.0 allOf trap was checked (the
generated type is a bare alias) and bd-5o3gt did not become two. The size bound
is maxDependencyAnchors, SHARED with the stored-edge read rather than given a
constant of its own: the two operations are asked about the same page of ids,
and two numbers would let a client ask one about a page the other refuses.
`dependencies.blocking` joins the capability vocabulary; `checkDatabaseSource`
grows a required role, which is the edit that reaches code this commit did not
write.
THE FLIP, one mode at a time and named as such in the code. FIRST `--json`:
the role's List runs the same LoadStoreListConfig, the same BuildListFilter and
the same workapi.FinishPage the branch ran longhand, so the page is unchanged
bytes and ErrTooManyRows still reaches handleMaxRowsError for exit 2. SECOND
every text rendering, with SkipCounts set — stage 1 added that field for this
arrival, and without it the flip would trade a plain scan for three aggregate
joins on the most-run command in the tree. THIRD the decoration.
WHAT STAYS OFF THE ROLE is --watch and the hierarchical --parent tree, the two
modes that consume the FILTER as a value. The bead also named --deps and
--format, and its stated reason — "reach no epilogue on either route" — is
false for both: they run FinishPage and printTruncationHint today. What is
genuinely off-role in those two is the WHOLE-GRAPH dependency-record load they
perform, which is neither a page nor the blocking decoration; their page comes
from the role like every other mode's. Recorded as A-blk-3 with the reading
this commit proceeded under, which is also the reading stage 1's own message
states ("stage 2 moves bd list's TEXT path onto the role").
The proxied route loses `runListProxiedReady`: --ready is ListRequest.ReadyFlag
and picking the ready query from it is the role's job on both routes. Two
functions differing only in which use-case method they called is the drift this
replaces.
PROVABLY INERT AT THE CLI, measured rather than argued: 31 `bd list` / `bd
children` invocations — every output mode, both cap knobs, --ready, --parent,
--format, --deps — run against a binary built from integration/facade-wave-3
and one built from this commit, over ONE shared workspace, differ on exactly
the two multi-blocker lines A-blk-2 predicts and nothing else in 687 lines. A
base-against-base run isolates the one other moving line as the
once-per-period install tip.
The forbidigo exception list did NOT shrink, and the count in
issueops/reader.go's claim is unchanged. cmd/bd/list.go and
list_proxied_server.go were never on it; cmd/bd/list_show_filter_modes.go still
is, because the tree walk, the watch loop, the proxied builder call and `bd
show --current` all still name the type. Said in the config rather than implied
by silence.
Verified: build, vet, gofmt clean; golangci-lint 0 issues; the seventeen new
cases at dolt, embeddeddolt (BEADS_TEST_EMBEDDED_DOLT=1) and uow, all green
with no skips; internal/httpapi and make api-check; internal/storage,
internal/telemetry, internal/jira, internal/workapi/..., issueops and the root
layering pins; the embedded `bd list`/`bd children`/max-rows CLI suites,
TestProxiedServerList under BEADS_TEST_PROXIED_SERVER=1 (58 subtests including
tree_parent, the three format modes, ready pagination and the three max-rows
refusals), TestProxiedLookup*, and the protocol corpus package.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
152 lines
6.7 KiB
Go
152 lines
6.7 KiB
Go
// Package storereader holds the store-backed implementation of
|
|
// issueops.Reader: one shared body that every store-shaped backend's
|
|
// IssueReader accessor hands back.
|
|
//
|
|
// It is a package of its own rather than a file in internal/workapi for one
|
|
// reason. internal/workapi is the builders' home and 22 cmd/bd files import
|
|
// it, so a constructor living there was a one-line drop-in replacement for
|
|
// store.IssueReader() from any front door — and one that silently skips the
|
|
// telemetry decorator's reader-level spans, because a decorator adds its layer
|
|
// in its own accessor. Down here the only importers are the two Dolt store
|
|
// packages, and the cmd-bd-role-constructors depguard rule in .golangci.yml
|
|
// makes a front door importing it a lint failure rather than a review comment.
|
|
//
|
|
// The accessor is the door. This is the thing behind it.
|
|
package storereader
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/steveyegge/beads/internal/storage"
|
|
"github.com/steveyegge/beads/internal/types"
|
|
"github.com/steveyegge/beads/internal/workapi"
|
|
"github.com/steveyegge/beads/issueops"
|
|
)
|
|
|
|
// New returns the issue-query surface backed by a store handle. *DoltStore and
|
|
// *EmbeddedDoltStore answer identically because the difference between them is
|
|
// below storage.DoltStorage, not above it.
|
|
//
|
|
// The reader supplies its own ConfigSource from the store it already holds, so
|
|
// a caller ON THE ROLE cannot half-perform the "load config, build filter,
|
|
// execute" ritual: it has no way to reach the pieces.
|
|
//
|
|
// THE BOUNDARY, stated once here because this is where the constructor lives:
|
|
// the store-backed role answers `bd show --json` and `bd list` on the DIRECT
|
|
// route, and the HTTP surface and both commands' proxied routes reach the
|
|
// uow-backed one. List below is therefore a traveled path on the most-run
|
|
// command in the tree, which it was not before: `bd list` used to build the
|
|
// filter and run this body's steps longhand.
|
|
//
|
|
// Ready below is still reached only by tests and by the HTTP surface. `bd
|
|
// ready` calls the workapi builders directly because it consumes the FILTER
|
|
// for --claim, --gated, --explain and --mol; see issueops.Reader's doc comment
|
|
// for why routing only its JSON path through the role would be worse.
|
|
func New(store storage.DoltStorage) (issueops.Reader, error) {
|
|
if store == nil {
|
|
return nil, &issueops.ErrUnsupported{Op: "storereader.New", Backend: "nil"}
|
|
}
|
|
return &storeReader{store: store}, nil
|
|
}
|
|
|
|
type storeReader struct{ store storage.DoltStorage }
|
|
|
|
var _ issueops.Reader = (*storeReader)(nil)
|
|
|
|
// offsetBackend names the backend an Offset refusal comes from. One name for
|
|
// both engines on purpose: the server-backed and embedded stores hand back
|
|
// THIS body, and it is the body — not the engine underneath it — that cannot
|
|
// page by offset.
|
|
const offsetBackend = "dolt-store"
|
|
|
|
// refuseOffset is the shared refusal. The store seam renders LIMIT without
|
|
// OFFSET (internal/storage/issueops/ready_work.go, search_counts.go), so a
|
|
// request carrying one used to come back as the unpaged first page with no
|
|
// error on it — a caller paging with Offset saw the same rows forever. The
|
|
// field is not dead: `bd ready/list/query --offset` are real flags, and their
|
|
// direct routes already reject a non-zero offset before reaching any of this
|
|
// (cmd/bd/ready.go, list.go, query.go). This is the same refusal one layer
|
|
// down, for the callers that are not the CLI.
|
|
func refuseOffset(op string) error {
|
|
return &issueops.ErrUnsupported{Op: op, Backend: offsetBackend}
|
|
}
|
|
|
|
func (r *storeReader) Ready(ctx context.Context, req issueops.ReadyRequest) (issueops.IssuePage, error) {
|
|
if req.Offset != 0 {
|
|
return issueops.IssuePage{}, refuseOffset("Reader.Ready(Offset)")
|
|
}
|
|
filter, err := workapi.BuildReadyFilter(req)
|
|
if err != nil {
|
|
return issueops.IssuePage{}, err
|
|
}
|
|
limit := filter.Limit
|
|
if limit > 0 {
|
|
// The store seam has no HasMore of its own, so ask for one row past
|
|
// the page and let its presence be the answer.
|
|
filter.Limit = limit + 1
|
|
}
|
|
items, err := r.store.GetReadyWorkWithCounts(ctx, filter)
|
|
if err != nil {
|
|
return issueops.IssuePage{}, err
|
|
}
|
|
// Ready has no display order to apply — the ordering is the sort POLICY
|
|
// the query ran under — so the epilogue's sort is a no-op here and only
|
|
// its trim and its verdict do any work. It is still the shared one: a
|
|
// second trim written out longhand is how the two arms of List came apart.
|
|
items, hasMore := workapi.FinishPage(items, "", false, limit, false)
|
|
return issueops.IssuePage{Items: items, HasMore: hasMore}, nil
|
|
}
|
|
|
|
// List answers one issue listing.
|
|
//
|
|
// The two knobs this body and its unit-of-work sibling answer differently sit
|
|
// side by side here and point opposite ways. Offset is refused below because
|
|
// this seam renders LIMIT without OFFSET. MaxRows is HONORED, and nothing
|
|
// below mentions it: the cap rides on the filter the shared builder produces,
|
|
// and the search path enforces it after the scan (internal/storage/issueops,
|
|
// EnforceMaxRowsCap), so the answer is *ErrTooManyRows instead of a page. The
|
|
// sibling refuses it, for the reason stated there.
|
|
func (r *storeReader) List(ctx context.Context, req issueops.ListRequest) (issueops.IssuePage, error) {
|
|
if req.Offset != 0 {
|
|
return issueops.IssuePage{}, refuseOffset("Reader.List(Offset)")
|
|
}
|
|
cfg, err := workapi.LoadStoreListConfig(ctx, r.store)
|
|
if err != nil {
|
|
return issueops.IssuePage{}, err
|
|
}
|
|
filter, err := workapi.BuildListFilter(req, cfg)
|
|
if err != nil {
|
|
return issueops.IssuePage{}, err
|
|
}
|
|
|
|
var items []*types.IssueWithCounts
|
|
if req.ReadyFlag {
|
|
items, err = r.store.GetReadyWorkWithCounts(ctx, workapi.ReadyFilterFromIssueFilter(workapi.WithFetchOneExtra(filter)))
|
|
} else {
|
|
items, err = r.store.SearchIssuesWithCounts(ctx, "", workapi.WithFetchOneExtra(filter))
|
|
}
|
|
if err != nil {
|
|
return issueops.IssuePage{}, err
|
|
}
|
|
|
|
// The sort, the trim and the HasMore verdict are workapi.FinishPage's, not
|
|
// this implementation's: `bd list` on both its routes and the uow-backed
|
|
// sibling of this method call the same function, so the only thing left
|
|
// that can differ between a CLI listing and an HTTP one is presentation.
|
|
// This seam reports no HasMore of its own, so the over-fetched row above
|
|
// is what speaks.
|
|
items, hasMore := workapi.FinishPage(items, req.SortBy, req.Reverse, workapi.PageLimit(req), false)
|
|
return issueops.IssuePage{Items: items, HasMore: hasMore}, nil
|
|
}
|
|
|
|
func (r *storeReader) Get(ctx context.Context, req issueops.GetRequest) (*issueops.IssueDetails, error) {
|
|
src := workapi.NewStoreDetailSource(r.store)
|
|
issue, isWisp, err := workapi.GetIssueOrWisp(ctx, src, req.ID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return workapi.BuildIssueDetails(ctx, src, issue, isWisp, workapi.DetailOptions{
|
|
IncludeDependents: req.IncludeDependents,
|
|
IncludeComments: req.IncludeComments,
|
|
})
|
|
}
|