feat(show): count-only JSON details with opt-in streamed payloads
Summary:
- Make default `bd show --json` emit relationship/comment counts without materializing dependents and comments.
- Add `--include-dependents` and `--include-comments` for callers that need full streamed payloads.
- Add Count* storage APIs and iterator APIs across Dolt, embedded Dolt, telemetry, and test stubs.
- Keep count and dependent-iterator semantics aligned with existing relationship APIs by including `wisp_dependencies`.
Verification:
- Full PR CI green at 3e036880f.
- go test -tags gms_pure_go ./cmd/bd -run 'TestShallowDependentsForJSON|TestIssueDetailsCountOnlyJSON' -count=1
Refs #4010.
Addresses be-ijck6q.
_codex-gpt-5.5-medium on behalf of matt wilkie_
Co-authored-by: Jim Wordelman <jim@wordelman.name>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
458cf899c2
commit
cfcc957995
22 changed files with 1812 additions and 67 deletions
120
cmd/bd/show.go
120
cmd/bd/show.go
|
|
@ -30,6 +30,8 @@ var showCmd = &cobra.Command{
|
|||
localTime, _ := cmd.Flags().GetBool("local-time")
|
||||
watchMode, _ := cmd.Flags().GetBool("watch")
|
||||
currentMode, _ := cmd.Flags().GetBool("current")
|
||||
includeDepends, _ := cmd.Flags().GetBool("include-dependents")
|
||||
includeComments, _ := cmd.Flags().GetBool("include-comments")
|
||||
ctx := rootCtx
|
||||
|
||||
// Helper to format timestamp based on --local-time flag
|
||||
|
|
@ -141,36 +143,76 @@ var showCmd = &cobra.Command{
|
|||
}
|
||||
|
||||
if jsonOutput {
|
||||
// Include labels, dependencies (with metadata), dependents (with metadata), and comments in JSON output
|
||||
// be-ijck6q: default is count-only (no dependents/comments slice in output).
|
||||
// Use --include-dependents / --include-comments to stream the full lists.
|
||||
details := &types.IssueDetails{Issue: *issue}
|
||||
details.Labels, _ = issueStore.GetLabels(ctx, issue.ID) // Best effort: show issue even if label fetch fails
|
||||
details.Labels, _ = issueStore.GetLabels(ctx, issue.ID)
|
||||
details.Dependencies, _ = issueStore.GetDependenciesWithMetadata(ctx, issue.ID)
|
||||
|
||||
// Get dependencies with metadata (dependency_type field)
|
||||
details.Dependencies, _ = issueStore.GetDependenciesWithMetadata(ctx, issue.ID) // Best effort: show issue even if deps unavailable
|
||||
details.Dependents, _ = issueStore.GetDependentsWithMetadata(ctx, issue.ID) // Best effort: show issue even if dependents unavailable
|
||||
// Aggregate counts — O(1) queries, no row materialization.
|
||||
depCount, _ := issueStore.CountDependents(ctx, issue.ID)
|
||||
details.DependentCount = &depCount
|
||||
depnCount, _ := issueStore.CountDependencies(ctx, issue.ID)
|
||||
details.DependencyCount = &depnCount
|
||||
cmtCount, _ := issueStore.CountIssueComments(ctx, issue.ID)
|
||||
details.CommentCount = &cmtCount
|
||||
|
||||
details.Comments, _ = issueStore.GetIssueComments(ctx, issue.ID) // Best effort: show issue even if comments unavailable
|
||||
// --include-dependents: stream via Iter, shallow-copy each item.
|
||||
// May be slow on hub beads with many dependents.
|
||||
if includeDepends {
|
||||
iter, err := issueStore.IterDependentsWithMetadata(ctx, issue.ID)
|
||||
if err == nil {
|
||||
defer iter.Close() //nolint:errcheck
|
||||
var shallowDeps []*types.IssueWithDependencyMetadata
|
||||
for iter.Next(ctx) {
|
||||
item := iter.Value()
|
||||
shallowDeps = append(shallowDeps, &types.IssueWithDependencyMetadata{
|
||||
Issue: types.Issue{
|
||||
ID: item.Issue.ID,
|
||||
Status: item.Issue.Status,
|
||||
IssueType: item.Issue.IssueType,
|
||||
Priority: item.Issue.Priority,
|
||||
Title: item.Issue.Title,
|
||||
},
|
||||
DependencyType: item.DependencyType,
|
||||
})
|
||||
}
|
||||
details.Dependents = shallowDeps
|
||||
|
||||
// Epic progress: count children status for epic issues
|
||||
if issue.IssueType == types.TypeEpic && details.Dependents != nil {
|
||||
total, closed := 0, 0
|
||||
for _, dep := range details.Dependents {
|
||||
if dep.DependencyType == types.DepParentChild {
|
||||
total++
|
||||
if dep.Issue.Status == types.StatusClosed {
|
||||
closed++
|
||||
// Epic progress from streamed dependents.
|
||||
if issue.IssueType == types.TypeEpic && len(shallowDeps) > 0 {
|
||||
total, closed := 0, 0
|
||||
for _, dep := range shallowDeps {
|
||||
if dep.DependencyType == types.DepParentChild {
|
||||
total++
|
||||
if dep.Issue.Status == types.StatusClosed {
|
||||
closed++
|
||||
}
|
||||
}
|
||||
}
|
||||
if total > 0 {
|
||||
details.EpicTotalChildren = &total
|
||||
details.EpicClosedChildren = &closed
|
||||
closeable := total == closed
|
||||
details.EpicCloseable = &closeable
|
||||
}
|
||||
}
|
||||
}
|
||||
if total > 0 {
|
||||
details.EpicTotalChildren = &total
|
||||
details.EpicClosedChildren = &closed
|
||||
closeable := total == closed
|
||||
details.EpicCloseable = &closeable
|
||||
}
|
||||
|
||||
// --include-comments: stream via Iter.
|
||||
// May be slow on issues with many comments.
|
||||
if includeComments {
|
||||
iter, err := issueStore.IterIssueComments(ctx, issue.ID)
|
||||
if err == nil {
|
||||
defer iter.Close() //nolint:errcheck
|
||||
for iter.Next(ctx) {
|
||||
details.Comments = append(details.Comments, iter.Value())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Compute parent from dependencies
|
||||
// Compute parent from dependencies.
|
||||
for _, dep := range details.Dependencies {
|
||||
if dep.DependencyType == types.DepParentChild {
|
||||
details.Parent = &dep.ID
|
||||
|
|
@ -178,7 +220,7 @@ var showCmd = &cobra.Command{
|
|||
}
|
||||
}
|
||||
allDetails = append(allDetails, details)
|
||||
result.Close() // Close before continuing to next iteration
|
||||
result.Close()
|
||||
continue
|
||||
}
|
||||
if idx > 0 {
|
||||
|
|
@ -390,6 +432,40 @@ var showCmd = &cobra.Command{
|
|||
},
|
||||
}
|
||||
|
||||
// shallowDependentsForJSON returns a copy of raw with each embedded Issue
|
||||
// stripped down to identity-and-shape fields (ID, Status, IssueType, Priority,
|
||||
// Title). The heavy fields (Description, Design, Notes, AcceptanceCriteria,
|
||||
// metadata blobs, etc.) are dropped.
|
||||
//
|
||||
// be-4d36f2: hub beads with thousands of dependents previously caused
|
||||
// `bd show --json <hub>` to allocate 5-13 GB while marshaling full Issue
|
||||
// records into JSON. The shallow shape preserves what callers actually
|
||||
// consume (counts, status, type) and drops what they don't (free-form
|
||||
// text fields). On a 4-dependent hub this trims output ~60%; on a hub
|
||||
// with thousands of dependents, savings scale linearly.
|
||||
func shallowDependentsForJSON(raw []*types.IssueWithDependencyMetadata) []*types.IssueWithDependencyMetadata {
|
||||
if len(raw) == 0 {
|
||||
return nil
|
||||
}
|
||||
shallow := make([]*types.IssueWithDependencyMetadata, 0, len(raw))
|
||||
for _, dep := range raw {
|
||||
if dep == nil {
|
||||
continue
|
||||
}
|
||||
shallow = append(shallow, &types.IssueWithDependencyMetadata{
|
||||
Issue: types.Issue{
|
||||
ID: dep.Issue.ID,
|
||||
Status: dep.Issue.Status,
|
||||
IssueType: dep.Issue.IssueType,
|
||||
Priority: dep.Issue.Priority,
|
||||
Title: dep.Issue.Title,
|
||||
},
|
||||
DependencyType: dep.DependencyType,
|
||||
})
|
||||
}
|
||||
return shallow
|
||||
}
|
||||
|
||||
func init() {
|
||||
showCmd.Flags().Bool("thread", false, "Show full conversation thread (for messages)")
|
||||
showCmd.Flags().Bool("short", false, "Show compact one-line output per issue")
|
||||
|
|
@ -401,6 +477,8 @@ func init() {
|
|||
showCmd.Flags().Bool("local-time", false, "Show timestamps in local time instead of UTC")
|
||||
showCmd.Flags().BoolP("watch", "w", false, "Watch for changes and auto-refresh display")
|
||||
showCmd.Flags().Bool("current", false, "Show the currently active issue (in-progress, hooked, or last touched)")
|
||||
showCmd.Flags().Bool("include-dependents", false, "Stream full dependent issues in JSON output (--json only; may be slow on hub beads)")
|
||||
showCmd.Flags().Bool("include-comments", false, "Stream full comment bodies in JSON output (--json only; may be slow on issues with many comments)")
|
||||
showCmd.ValidArgsFunction = issueIDCompletion
|
||||
rootCmd.AddCommand(showCmd)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -167,10 +167,28 @@ func TestEmbeddedShow(t *testing.T) {
|
|||
_, _ = store.AddIssueComment(t.Context(), issue.ID, "tester", "A comment")
|
||||
store.Close() // release flock before subprocess
|
||||
|
||||
m := bdShowDetails(t, bd, dir, issue.ID)
|
||||
// Comments are count-only by default; --include-comments streams them.
|
||||
out, err := bdRunWithFlockRetry(t, bd, dir, "show", issue.ID, "--json", "--include-comments")
|
||||
if err != nil {
|
||||
t.Fatalf("bd show --include-comments failed: %v\n%s", err, out)
|
||||
}
|
||||
s := strings.TrimSpace(string(out))
|
||||
if start := strings.IndexAny(s, "[{"); start >= 0 {
|
||||
s = s[start:]
|
||||
}
|
||||
var m map[string]interface{}
|
||||
if strings.HasPrefix(s, "[") {
|
||||
var arr []map[string]interface{}
|
||||
if jerr := json.Unmarshal([]byte(s), &arr); jerr != nil || len(arr) == 0 {
|
||||
t.Fatalf("parse show JSON array: %v\n%s", jerr, s)
|
||||
}
|
||||
m = arr[0]
|
||||
} else if jerr := json.Unmarshal([]byte(s), &m); jerr != nil {
|
||||
t.Fatalf("parse show JSON: %v\n%s", jerr, s)
|
||||
}
|
||||
comments, _ := m["comments"].([]interface{})
|
||||
if len(comments) == 0 {
|
||||
t.Error("expected comments in JSON output")
|
||||
t.Error("expected comments in JSON output with --include-comments")
|
||||
}
|
||||
})
|
||||
|
||||
|
|
|
|||
158
cmd/bd/show_shallow_dependents_test.go
Normal file
158
cmd/bd/show_shallow_dependents_test.go
Normal file
|
|
@ -0,0 +1,158 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
)
|
||||
|
||||
// TestShallowDependentsForJSON_StripsHeavyFields is the regression guard for
|
||||
// be-4d36f2: bd show --json must not embed the heavy free-form fields
|
||||
// (Description, Design, Notes, AcceptanceCriteria) of every dependent into
|
||||
// the output. On hub beads with thousands of dependents this previously
|
||||
// allocated 5-13 GB.
|
||||
func TestShallowDependentsForJSON_StripsHeavyFields(t *testing.T) {
|
||||
heavy := strings.Repeat("x", 1024) // simulate a long free-form field
|
||||
raw := []*types.IssueWithDependencyMetadata{
|
||||
{
|
||||
Issue: types.Issue{
|
||||
ID: "be-1",
|
||||
Status: types.StatusOpen,
|
||||
IssueType: types.TypeTask,
|
||||
Priority: 1,
|
||||
Title: "title 1",
|
||||
Description: heavy,
|
||||
Design: heavy,
|
||||
Notes: heavy,
|
||||
AcceptanceCriteria: heavy,
|
||||
},
|
||||
DependencyType: types.DepBlocks,
|
||||
},
|
||||
{
|
||||
Issue: types.Issue{
|
||||
ID: "be-2",
|
||||
Status: types.StatusClosed,
|
||||
IssueType: types.TypeBug,
|
||||
Priority: 2,
|
||||
Title: "title 2",
|
||||
Description: heavy,
|
||||
},
|
||||
DependencyType: types.DepParentChild,
|
||||
},
|
||||
}
|
||||
|
||||
got := shallowDependentsForJSON(raw)
|
||||
if len(got) != 2 {
|
||||
t.Fatalf("got %d entries, want 2", len(got))
|
||||
}
|
||||
|
||||
for i, dep := range got {
|
||||
if dep == nil {
|
||||
t.Fatalf("entry %d nil", i)
|
||||
}
|
||||
// Identity-and-shape fields preserved
|
||||
if dep.Issue.ID != raw[i].Issue.ID {
|
||||
t.Errorf("entry %d: ID got %q want %q", i, dep.Issue.ID, raw[i].Issue.ID)
|
||||
}
|
||||
if dep.Issue.Status != raw[i].Issue.Status {
|
||||
t.Errorf("entry %d: Status got %q want %q", i, dep.Issue.Status, raw[i].Issue.Status)
|
||||
}
|
||||
if dep.Issue.IssueType != raw[i].Issue.IssueType {
|
||||
t.Errorf("entry %d: IssueType got %q want %q", i, dep.Issue.IssueType, raw[i].Issue.IssueType)
|
||||
}
|
||||
if dep.Issue.Priority != raw[i].Issue.Priority {
|
||||
t.Errorf("entry %d: Priority got %d want %d", i, dep.Issue.Priority, raw[i].Issue.Priority)
|
||||
}
|
||||
if dep.Issue.Title != raw[i].Issue.Title {
|
||||
t.Errorf("entry %d: Title got %q want %q", i, dep.Issue.Title, raw[i].Issue.Title)
|
||||
}
|
||||
if dep.DependencyType != raw[i].DependencyType {
|
||||
t.Errorf("entry %d: DependencyType got %q want %q", i, dep.DependencyType, raw[i].DependencyType)
|
||||
}
|
||||
// Heavy fields stripped
|
||||
if dep.Issue.Description != "" {
|
||||
t.Errorf("entry %d: Description not stripped (len=%d)", i, len(dep.Issue.Description))
|
||||
}
|
||||
if dep.Issue.Design != "" {
|
||||
t.Errorf("entry %d: Design not stripped (len=%d)", i, len(dep.Issue.Design))
|
||||
}
|
||||
if dep.Issue.Notes != "" {
|
||||
t.Errorf("entry %d: Notes not stripped (len=%d)", i, len(dep.Issue.Notes))
|
||||
}
|
||||
if dep.Issue.AcceptanceCriteria != "" {
|
||||
t.Errorf("entry %d: AcceptanceCriteria not stripped (len=%d)", i, len(dep.Issue.AcceptanceCriteria))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestShallowDependentsForJSON_NilAndEmpty(t *testing.T) {
|
||||
if got := shallowDependentsForJSON(nil); got != nil {
|
||||
t.Errorf("nil input: got non-nil (%d entries)", len(got))
|
||||
}
|
||||
if got := shallowDependentsForJSON([]*types.IssueWithDependencyMetadata{}); got != nil {
|
||||
t.Errorf("empty input: got non-nil (%d entries)", len(got))
|
||||
}
|
||||
}
|
||||
|
||||
func TestShallowDependentsForJSON_SkipsNilEntries(t *testing.T) {
|
||||
raw := []*types.IssueWithDependencyMetadata{
|
||||
nil,
|
||||
{Issue: types.Issue{ID: "be-1"}, DependencyType: types.DepBlocks},
|
||||
nil,
|
||||
{Issue: types.Issue{ID: "be-2"}, DependencyType: types.DepBlocks},
|
||||
}
|
||||
got := shallowDependentsForJSON(raw)
|
||||
if len(got) != 2 {
|
||||
t.Fatalf("got %d entries, want 2 (nils skipped)", len(got))
|
||||
}
|
||||
if got[0].Issue.ID != "be-1" || got[1].Issue.ID != "be-2" {
|
||||
t.Errorf("unexpected IDs: %q, %q", got[0].Issue.ID, got[1].Issue.ID)
|
||||
}
|
||||
}
|
||||
|
||||
// TestIssueDetailsCountOnlyJSON is the regression guard for be-ijck6q:
|
||||
// the default bd show --json output must emit dependent_count / comment_count
|
||||
// as count-only fields and must NOT include a "dependents" or "comments" key
|
||||
// when --include-dependents / --include-comments are not given.
|
||||
func TestIssueDetailsCountOnlyJSON(t *testing.T) {
|
||||
depCount := int64(42)
|
||||
depnCount := int64(3)
|
||||
cmtCount := int64(7)
|
||||
details := &types.IssueDetails{
|
||||
Issue: types.Issue{
|
||||
ID: "be-abc",
|
||||
Title: "Test issue",
|
||||
},
|
||||
DependentCount: &depCount,
|
||||
DependencyCount: &depnCount,
|
||||
CommentCount: &cmtCount,
|
||||
// Dependents and Comments intentionally nil (count-only mode)
|
||||
}
|
||||
|
||||
data, err := json.Marshal(details)
|
||||
if err != nil {
|
||||
t.Fatalf("marshal: %v", err)
|
||||
}
|
||||
js := string(data)
|
||||
|
||||
// Count fields must be present.
|
||||
if !strings.Contains(js, `"dependent_count":42`) {
|
||||
t.Errorf("expected dependent_count:42 in JSON, got: %s", js)
|
||||
}
|
||||
if !strings.Contains(js, `"dependency_count":3`) {
|
||||
t.Errorf("expected dependency_count:3 in JSON, got: %s", js)
|
||||
}
|
||||
if !strings.Contains(js, `"comment_count":7`) {
|
||||
t.Errorf("expected comment_count:7 in JSON, got: %s", js)
|
||||
}
|
||||
|
||||
// Slice fields must be absent (omitempty, nil → omitted).
|
||||
if strings.Contains(js, `"dependents"`) {
|
||||
t.Errorf("expected no dependents key in count-only output, got: %s", js)
|
||||
}
|
||||
if strings.Contains(js, `"comments"`) {
|
||||
t.Errorf("expected no comments key in count-only output, got: %s", js)
|
||||
}
|
||||
}
|
||||
|
|
@ -1305,16 +1305,18 @@ bd show [id...] [--id=<id>...] [--current] [flags]
|
|||
**Flags:**
|
||||
|
||||
```
|
||||
--as-of string Show issue as it existed at a specific commit hash or branch (requires Dolt)
|
||||
--children Show only the children of this issue
|
||||
--current Show the currently active issue (in-progress, hooked, or last touched)
|
||||
--id stringArray Issue ID (use for IDs that look like flags, e.g., --id=gt--xyz)
|
||||
--local-time Show timestamps in local time instead of UTC
|
||||
--long Show all available fields (extended metadata, agent identity, gate fields, etc.)
|
||||
--refs Show issues that reference this issue (reverse lookup)
|
||||
--short Show compact one-line output per issue
|
||||
--thread Show full conversation thread (for messages)
|
||||
-w, --watch Watch for changes and auto-refresh display
|
||||
--as-of string Show issue as it existed at a specific commit hash or branch (requires Dolt)
|
||||
--children Show only the children of this issue
|
||||
--current Show the currently active issue (in-progress, hooked, or last touched)
|
||||
--id stringArray Issue ID (use for IDs that look like flags, e.g., --id=gt--xyz)
|
||||
--include-comments Stream full comment bodies in JSON output (--json only; may be slow on issues with many comments)
|
||||
--include-dependents Stream full dependent issues in JSON output (--json only; may be slow on hub beads)
|
||||
--local-time Show timestamps in local time instead of UTC
|
||||
--long Show all available fields (extended metadata, agent identity, gate fields, etc.)
|
||||
--refs Show issues that reference this issue (reverse lookup)
|
||||
--short Show compact one-line output per issue
|
||||
--thread Show full conversation thread (for messages)
|
||||
-w, --watch Watch for changes and auto-refresh display
|
||||
```
|
||||
|
||||
### bd state
|
||||
|
|
|
|||
|
|
@ -627,7 +627,48 @@ func (s *configStore) SlotGet(_ context.Context, _, _ string) (string, error) {
|
|||
return "", nil
|
||||
}
|
||||
func (s *configStore) SlotClear(_ context.Context, _, _, _ string) error { return nil }
|
||||
func (s *configStore) Close() error { return nil }
|
||||
|
||||
func (s *configStore) CountIssues(_ context.Context, _ string, _ types.IssueFilter) (int64, error) {
|
||||
return 0, nil
|
||||
}
|
||||
func (s *configStore) CountDependents(_ context.Context, _ string) (int64, error) { return 0, nil }
|
||||
func (s *configStore) CountDependencies(_ context.Context, _ string) (int64, error) { return 0, nil }
|
||||
func (s *configStore) CountIssueComments(_ context.Context, _ string) (int64, error) {
|
||||
return 0, nil
|
||||
}
|
||||
func (s *configStore) CountEvents(_ context.Context, _ string, _ int) (int64, error) {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
func (s *configStore) IterIssues(_ context.Context, _ string, _ types.IssueFilter) (storage.Iter[types.Issue], error) {
|
||||
return storage.NewSliceIter[types.Issue](nil), nil
|
||||
}
|
||||
func (s *configStore) IterDependentsWithMetadata(_ context.Context, _ string) (storage.Iter[types.IssueWithDependencyMetadata], error) {
|
||||
return storage.NewSliceIter[types.IssueWithDependencyMetadata](nil), nil
|
||||
}
|
||||
func (s *configStore) IterDependenciesWithMetadata(_ context.Context, _ string) (storage.Iter[types.IssueWithDependencyMetadata], error) {
|
||||
return storage.NewSliceIter[types.IssueWithDependencyMetadata](nil), nil
|
||||
}
|
||||
func (s *configStore) IterIssueComments(_ context.Context, _ string) (storage.Iter[types.Comment], error) {
|
||||
return storage.NewSliceIter[types.Comment](nil), nil
|
||||
}
|
||||
func (s *configStore) IterEvents(_ context.Context, _ string, _ int) (storage.Iter[types.Event], error) {
|
||||
return storage.NewSliceIter[types.Event](nil), nil
|
||||
}
|
||||
func (s *configStore) IterAllEventsSince(_ context.Context, _ time.Time) (storage.Iter[types.Event], error) {
|
||||
return storage.NewSliceIter[types.Event](nil), nil
|
||||
}
|
||||
func (s *configStore) IterReadyWork(_ context.Context, _ types.WorkFilter) (storage.Iter[types.Issue], error) {
|
||||
return storage.NewSliceIter[types.Issue](nil), nil
|
||||
}
|
||||
func (s *configStore) IterBlockedIssues(_ context.Context, _ types.WorkFilter) (storage.Iter[types.BlockedIssue], error) {
|
||||
return storage.NewSliceIter[types.BlockedIssue](nil), nil
|
||||
}
|
||||
func (s *configStore) IterWisps(_ context.Context, _ types.WispFilter) (storage.Iter[types.Issue], error) {
|
||||
return storage.NewSliceIter[types.Issue](nil), nil
|
||||
}
|
||||
|
||||
func (s *configStore) Close() error { return nil }
|
||||
|
||||
func TestFetchIssuesIncludesPullJQLInQuery(t *testing.T) {
|
||||
var capturedJQL string
|
||||
|
|
|
|||
|
|
@ -17,4 +17,15 @@ type DependencyQueryStore interface {
|
|||
GetNewlyUnblockedByClose(ctx context.Context, closedIssueID string) ([]*types.Issue, error)
|
||||
DetectCycles(ctx context.Context) ([][]*types.Issue, error)
|
||||
FindWispDependentsRecursive(ctx context.Context, ids []string) (map[string]bool, error)
|
||||
|
||||
// IterAllDependencyRecords streams every dependency edge in the rig as
|
||||
// a flat sequence of *types.Dependency rows. Callers that today walk
|
||||
// GetAllDependencyRecords (which returns map[string][]*types.Dependency)
|
||||
// can rebuild that map by streaming and grouping on Dependency.IssueID.
|
||||
IterAllDependencyRecords(ctx context.Context) (Iter[types.Dependency], error)
|
||||
|
||||
// CountDependentsByStatus returns the number of issues that depend on issueID
|
||||
// and are in the given status. Preferred over CountDependents + per-row filtering
|
||||
// for the bd close epic-closure check.
|
||||
CountDependentsByStatus(ctx context.Context, issueID string, status types.Status) (int64, error)
|
||||
}
|
||||
|
|
|
|||
149
internal/storage/dolt/counts.go
Normal file
149
internal/storage/dolt/counts.go
Normal file
|
|
@ -0,0 +1,149 @@
|
|||
package dolt
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/steveyegge/beads/internal/storage/issueops"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
)
|
||||
|
||||
// depTargetExpr resolves a dependency row's target id from the split physical
|
||||
// columns instead of the STORED generated `depends_on_id` column. Both
|
||||
// `dependencies` and `wisp_dependencies` define depends_on_id as
|
||||
// GENERATED ALWAYS AS (COALESCE(depends_on_issue_id, depends_on_wisp_id,
|
||||
// depends_on_external)). Count queries must filter on the base columns: inside
|
||||
// a count(*) (which projects no real columns) the pure-Go GMS analyzer can
|
||||
// prune the base columns the generated column derives from and then fail with
|
||||
// "column depends_on_id could not be found in any table in scope". The slice
|
||||
// path projects real columns, so it can use depends_on_id directly. This
|
||||
// matches issueops.DepTargetExpr on main.
|
||||
const depTargetExpr = "COALESCE(depends_on_issue_id, depends_on_wisp_id, depends_on_external)"
|
||||
|
||||
// CountIssues returns the number of issues matching query and filter.
|
||||
// Filter.Limit and Filter.Offset are ignored; all other fields apply.
|
||||
func (s *DoltStore) CountIssues(ctx context.Context, query string, filter types.IssueFilter) (int64, error) {
|
||||
var n int64
|
||||
err := s.withReadTx(ctx, func(tx *sql.Tx) error {
|
||||
whereClauses, args, err := issueops.BuildIssueFilterClauses(query, filter, issueops.IssuesFilterTables)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
where := ""
|
||||
if len(whereClauses) > 0 {
|
||||
where = " WHERE " + strings.Join(whereClauses, " AND ")
|
||||
}
|
||||
//nolint:gosec // table name is a static constant; placeholders are bound
|
||||
q := fmt.Sprintf(`SELECT count(*) FROM issues%s`, where)
|
||||
return tx.QueryRowContext(ctx, q, args...).Scan(&n)
|
||||
})
|
||||
return n, err
|
||||
}
|
||||
|
||||
// CountDependents returns the number of issues that depend on issueID.
|
||||
// Counts both dependency tables so the total matches GetDependentsWithMetadata:
|
||||
// a dependent may be a permanent issue (edge in `dependencies`) or a wisp
|
||||
// (edge in `wisp_dependencies`, routed there by WispTableRouting on the source).
|
||||
//
|
||||
// Both tables' targets are resolved via depTargetExpr (the split physical
|
||||
// columns) rather than the STORED generated depends_on_id, which a count(*)
|
||||
// can fail to resolve under the pure-Go GMS analyzer.
|
||||
func (s *DoltStore) CountDependents(ctx context.Context, issueID string) (int64, error) {
|
||||
var n int64
|
||||
err := s.withReadTx(ctx, func(tx *sql.Tx) error {
|
||||
var perm, wisp int64
|
||||
if err := tx.QueryRowContext(ctx,
|
||||
`SELECT count(*) FROM dependencies WHERE `+depTargetExpr+` = ?`, issueID).Scan(&perm); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := tx.QueryRowContext(ctx,
|
||||
`SELECT count(*) FROM wisp_dependencies WHERE `+depTargetExpr+` = ?`, issueID).Scan(&wisp); err != nil {
|
||||
return err
|
||||
}
|
||||
n = perm + wisp
|
||||
return nil
|
||||
})
|
||||
return n, err
|
||||
}
|
||||
|
||||
// CountDependencies returns the number of issues that issueID depends on.
|
||||
// Counts both dependency tables so the total matches GetDependenciesWithMetadata:
|
||||
// a wisp's outgoing edges live in `wisp_dependencies`, a permanent issue's in
|
||||
// `dependencies`. Counted as two separate queries summed in Go (see
|
||||
// CountDependents for why a single combined query is avoided).
|
||||
func (s *DoltStore) CountDependencies(ctx context.Context, issueID string) (int64, error) {
|
||||
var n int64
|
||||
err := s.withReadTx(ctx, func(tx *sql.Tx) error {
|
||||
var perm, wisp int64
|
||||
if err := tx.QueryRowContext(ctx,
|
||||
`SELECT count(*) FROM dependencies WHERE issue_id = ?`, issueID).Scan(&perm); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := tx.QueryRowContext(ctx,
|
||||
`SELECT count(*) FROM wisp_dependencies WHERE issue_id = ?`, issueID).Scan(&wisp); err != nil {
|
||||
return err
|
||||
}
|
||||
n = perm + wisp
|
||||
return nil
|
||||
})
|
||||
return n, err
|
||||
}
|
||||
|
||||
// CountIssueComments returns the number of comments on an issue.
|
||||
func (s *DoltStore) CountIssueComments(ctx context.Context, issueID string) (int64, error) {
|
||||
var n int64
|
||||
err := s.withReadTx(ctx, func(tx *sql.Tx) error {
|
||||
return tx.QueryRowContext(ctx,
|
||||
`SELECT count(*) FROM comments WHERE issue_id = ?`, issueID).Scan(&n)
|
||||
})
|
||||
return n, err
|
||||
}
|
||||
|
||||
// CountEvents returns the number of audit events for an issue, capped at limit
|
||||
// (or unbounded if limit == 0).
|
||||
func (s *DoltStore) CountEvents(ctx context.Context, issueID string, limit int) (int64, error) {
|
||||
var n int64
|
||||
err := s.withReadTx(ctx, func(tx *sql.Tx) error {
|
||||
return tx.QueryRowContext(ctx,
|
||||
`SELECT count(*) FROM events WHERE issue_id = ?`, issueID).Scan(&n)
|
||||
})
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if limit > 0 && n > int64(limit) {
|
||||
n = int64(limit)
|
||||
}
|
||||
return n, nil
|
||||
}
|
||||
|
||||
// CountDependentsByStatus returns the number of issues that depend on issueID
|
||||
// and are in the given status. Counts both dependency tables, joining each to
|
||||
// its home issue table (dependencies→issues, wisp_dependencies→wisps), so wisp
|
||||
// dependents are included the same way GetDependentsWithMetadata includes them.
|
||||
// Counted as two separate queries summed in Go (see CountDependents for why a
|
||||
// single combined query is avoided).
|
||||
func (s *DoltStore) CountDependentsByStatus(ctx context.Context, issueID string, status types.Status) (int64, error) {
|
||||
var n int64
|
||||
err := s.withReadTx(ctx, func(tx *sql.Tx) error {
|
||||
var perm, wisp int64
|
||||
if err := tx.QueryRowContext(ctx,
|
||||
`SELECT count(*) FROM dependencies d
|
||||
JOIN issues i ON i.id = d.issue_id
|
||||
WHERE COALESCE(d.depends_on_issue_id, d.depends_on_wisp_id, d.depends_on_external) = ? AND i.status = ?`,
|
||||
issueID, string(status)).Scan(&perm); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := tx.QueryRowContext(ctx,
|
||||
`SELECT count(*) FROM wisp_dependencies d
|
||||
JOIN wisps w ON w.id = d.issue_id
|
||||
WHERE COALESCE(d.depends_on_issue_id, d.depends_on_wisp_id, d.depends_on_external) = ? AND w.status = ?`,
|
||||
issueID, string(status)).Scan(&wisp); err != nil {
|
||||
return err
|
||||
}
|
||||
n = perm + wisp
|
||||
return nil
|
||||
})
|
||||
return n, err
|
||||
}
|
||||
97
internal/storage/dolt/counts_wisp_test.go
Normal file
97
internal/storage/dolt/counts_wisp_test.go
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
package dolt
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
)
|
||||
|
||||
// TestCountAndIterIncludeWispDependencies is the regression guard for the
|
||||
// PR #4010 review (be-xbl83). The Count*/Iter* paths that feed
|
||||
// `bd show --json` (DependentCount/DependencyCount and --include-dependents)
|
||||
// must include `wisp_dependencies` edges, matching the slice-path relationship
|
||||
// APIs (GetDependentsWithMetadata / GetDependenciesWithMetadata) that the
|
||||
// human-readable `bd show` already uses.
|
||||
//
|
||||
// Before the fix, CountDependents, CountDependencies, CountDependentsByStatus,
|
||||
// and the streaming IterDependentsWithMetadata queried only the `dependencies`
|
||||
// table. A permanent issue with a wisp dependent therefore reported a
|
||||
// too-small dependent_count and omitted the wisp from --include-dependents,
|
||||
// contradicting the `dependents` slice in the same output.
|
||||
func TestCountAndIterIncludeWispDependencies(t *testing.T) {
|
||||
store, cleanup := setupTestStore(t)
|
||||
defer cleanup()
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
|
||||
defer cancel()
|
||||
|
||||
// Build: wc-perm-dep --blocks--> wc-target (edge in `dependencies`)
|
||||
// wc-wisp-dep --blocks--> wc-target (edge in `wisp_dependencies`)
|
||||
// so wc-target has one permanent and one wisp dependent.
|
||||
createPerm(t, ctx, store, "wc-target")
|
||||
createPerm(t, ctx, store, "wc-perm-dep")
|
||||
createWisp(t, ctx, store, "wc-wisp-dep")
|
||||
|
||||
addBlocks := func(src, tgt string) {
|
||||
t.Helper()
|
||||
if err := store.AddDependency(ctx, &types.Dependency{
|
||||
IssueID: src,
|
||||
DependsOnID: tgt,
|
||||
Type: types.DepBlocks,
|
||||
}, "tester"); err != nil {
|
||||
t.Fatalf("add dependency %s -> %s: %v", src, tgt, err)
|
||||
}
|
||||
}
|
||||
addBlocks("wc-perm-dep", "wc-target")
|
||||
addBlocks("wc-wisp-dep", "wc-target")
|
||||
|
||||
// Precondition: the slice path bd show's human output uses already counts
|
||||
// both dependents. The new count/iter paths must agree with it.
|
||||
deps, err := store.GetDependentsWithMetadata(ctx, "wc-target")
|
||||
if err != nil {
|
||||
t.Fatalf("GetDependentsWithMetadata: %v", err)
|
||||
}
|
||||
if len(deps) != 2 {
|
||||
t.Fatalf("precondition: GetDependentsWithMetadata(wc-target) = %d, want 2", len(deps))
|
||||
}
|
||||
|
||||
// CountDependents must include the wisp dependent.
|
||||
if n, err := store.CountDependents(ctx, "wc-target"); err != nil {
|
||||
t.Fatalf("CountDependents: %v", err)
|
||||
} else if n != 2 {
|
||||
t.Errorf("CountDependents(wc-target) = %d, want 2 (1 perm + 1 wisp); wisp_dependencies edge dropped", n)
|
||||
}
|
||||
|
||||
// CountDependentsByStatus must include the wisp dependent (both are open).
|
||||
if n, err := store.CountDependentsByStatus(ctx, "wc-target", types.StatusOpen); err != nil {
|
||||
t.Fatalf("CountDependentsByStatus: %v", err)
|
||||
} else if n != 2 {
|
||||
t.Errorf("CountDependentsByStatus(wc-target, open) = %d, want 2", n)
|
||||
}
|
||||
|
||||
// CountDependencies on the wisp source must count its wisp_dependencies edge.
|
||||
if n, err := store.CountDependencies(ctx, "wc-wisp-dep"); err != nil {
|
||||
t.Fatalf("CountDependencies: %v", err)
|
||||
} else if n != 1 {
|
||||
t.Errorf("CountDependencies(wc-wisp-dep) = %d, want 1 (edge lives in wisp_dependencies)", n)
|
||||
}
|
||||
|
||||
// IterDependentsWithMetadata must stream BOTH dependents.
|
||||
iter, err := store.IterDependentsWithMetadata(ctx, "wc-target")
|
||||
if err != nil {
|
||||
t.Fatalf("IterDependentsWithMetadata: %v", err)
|
||||
}
|
||||
defer iter.Close() //nolint:errcheck
|
||||
seen := map[string]bool{}
|
||||
for iter.Next(ctx) {
|
||||
seen[iter.Value().Issue.ID] = true
|
||||
}
|
||||
if err := iter.Err(); err != nil {
|
||||
t.Fatalf("IterDependentsWithMetadata iterate: %v", err)
|
||||
}
|
||||
if !seen["wc-perm-dep"] || !seen["wc-wisp-dep"] {
|
||||
t.Errorf("IterDependentsWithMetadata(wc-target) streamed %v, want both wc-perm-dep and wc-wisp-dep", seen)
|
||||
}
|
||||
}
|
||||
242
internal/storage/dolt/iter_dependents.go
Normal file
242
internal/storage/dolt/iter_dependents.go
Normal file
|
|
@ -0,0 +1,242 @@
|
|||
// Package dolt — iter_dependents.go
|
||||
//
|
||||
// Streaming iterator over the issues × dependencies join. Same dedicated-
|
||||
// conn pattern as iter_issues.go — labels (when needed) hydrate on a
|
||||
// second pool connection so the cursor never deadlocks.
|
||||
//
|
||||
// Both dependency tables are included so results match the slice path
|
||||
// GetDependentsWithMetadata, which the human-readable `bd show` uses.
|
||||
// IterDependentsWithMetadata UNION ALLs `dependencies` (permanent-source
|
||||
// edges, joined to `issues`) with `wisp_dependencies` (wisp-source edges,
|
||||
// joined to `wisps`). WispTableRouting routes every edge to exactly one table
|
||||
// by its source's wisp status, so each edge table joins cleanly to its source
|
||||
// and no row is double-counted. IterDependenciesWithMetadata delegates to the
|
||||
// slice path: a dependency's *target* may be permanent or wisp independent of
|
||||
// which table holds the edge, which a single streaming join cannot resolve,
|
||||
// and the method has no streaming caller today.
|
||||
package dolt
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
|
||||
"github.com/steveyegge/beads/internal/storage"
|
||||
"github.com/steveyegge/beads/internal/storage/issueops"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
)
|
||||
|
||||
// doltDependentsIter streams the issues × dependency join, returning each
|
||||
// row as an IssueWithDependencyMetadata. Used by both IterDependents-
|
||||
// WithMetadata and IterDependenciesWithMetadata; the SQL differs only in
|
||||
// which side of the dependencies join is bound to issueID.
|
||||
type doltDependentsIter struct {
|
||||
s *DoltStore
|
||||
conn *sql.Conn
|
||||
rows *sql.Rows
|
||||
cur *types.IssueWithDependencyMetadata
|
||||
err error
|
||||
closed bool
|
||||
}
|
||||
|
||||
// IterDependentsWithMetadata streams dependents (issues that depend on
|
||||
// issueID) with the relationship type attached. Includes both permanent
|
||||
// (`dependencies`) and wisp (`wisp_dependencies`) dependents so the stream
|
||||
// matches GetDependentsWithMetadata. See the package doc for why the join
|
||||
// target per edge table is unambiguous.
|
||||
func (s *DoltStore) IterDependentsWithMetadata(ctx context.Context, issueID string) (storage.Iter[types.IssueWithDependencyMetadata], error) {
|
||||
q := fmt.Sprintf(`
|
||||
SELECT %s, d.type
|
||||
FROM issues i
|
||||
JOIN dependencies d ON d.issue_id = i.id
|
||||
WHERE d.depends_on_id = ?
|
||||
UNION ALL
|
||||
SELECT %s, d.type
|
||||
FROM wisps w
|
||||
JOIN wisp_dependencies d ON d.issue_id = w.id
|
||||
WHERE d.depends_on_id = ?
|
||||
ORDER BY created_at ASC
|
||||
`, prefixedIssueColumns("i"), prefixedIssueColumns("w"))
|
||||
return s.iterIssuesWithDepType(ctx, q, issueID, issueID)
|
||||
}
|
||||
|
||||
// IterDependenciesWithMetadata streams dependencies (issues issueID depends
|
||||
// on) with the relationship type attached. It delegates to the slice path
|
||||
// GetDependenciesWithMetadata (which resolves targets across both `issues`
|
||||
// and `wisps`) rather than a streaming join, because a dependency's target
|
||||
// table cannot be determined from the edge table alone. There is no streaming
|
||||
// caller for this direction today; revisit if one appears.
|
||||
func (s *DoltStore) IterDependenciesWithMetadata(ctx context.Context, issueID string) (storage.Iter[types.IssueWithDependencyMetadata], error) {
|
||||
deps, err := s.GetDependenciesWithMetadata(ctx, issueID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return storage.NewSliceIter(deps), nil
|
||||
}
|
||||
|
||||
func (s *DoltStore) iterIssuesWithDepType(ctx context.Context, q string, args ...any) (storage.Iter[types.IssueWithDependencyMetadata], error) {
|
||||
if s.closed.Load() {
|
||||
return nil, ErrStoreClosed
|
||||
}
|
||||
conn, err := s.db.Conn(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("iter dependents: acquire conn: %w", err)
|
||||
}
|
||||
rows, err := conn.QueryContext(ctx, q, args...)
|
||||
if err != nil {
|
||||
_ = conn.Close()
|
||||
return nil, fmt.Errorf("iter dependents: query: %w", err)
|
||||
}
|
||||
return &doltDependentsIter{s: s, conn: conn, rows: rows}, nil
|
||||
}
|
||||
|
||||
func (it *doltDependentsIter) Next(ctx context.Context) bool {
|
||||
if it.err != nil || it.closed {
|
||||
return false
|
||||
}
|
||||
if err := ctx.Err(); err != nil {
|
||||
it.err = err
|
||||
return false
|
||||
}
|
||||
if !it.rows.Next() {
|
||||
it.err = it.rows.Err()
|
||||
return false
|
||||
}
|
||||
iss, depType, err := scanIssueWithDepTypeFrom(it.rows)
|
||||
if err != nil {
|
||||
it.err = fmt.Errorf("iter dependents: scan: %w", err)
|
||||
return false
|
||||
}
|
||||
// NOTE: labels are NOT hydrated here. The corresponding slice path
|
||||
// (GetDependentsWithMetadata in dolt/dependencies.go) does not hydrate
|
||||
// either, so this matches for parity. Callers that need labels on
|
||||
// dependents must call GetLabels(id) explicitly.
|
||||
it.cur = &types.IssueWithDependencyMetadata{
|
||||
Issue: *iss,
|
||||
DependencyType: types.DependencyType(depType),
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (it *doltDependentsIter) Value() *types.IssueWithDependencyMetadata { return it.cur }
|
||||
func (it *doltDependentsIter) Err() error { return it.err }
|
||||
|
||||
func (it *doltDependentsIter) Close() error {
|
||||
if it.closed {
|
||||
return nil
|
||||
}
|
||||
it.closed = true
|
||||
if it.rows != nil {
|
||||
_ = it.rows.Close()
|
||||
}
|
||||
if it.conn != nil {
|
||||
_ = it.conn.Close()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// prefixedIssueColumns returns IssueSelectColumns with each column prefixed
|
||||
// by the given table alias (e.g. "i") so it can be used in JOIN queries.
|
||||
// The columns string is a comma-separated list with newlines/whitespace;
|
||||
// we split on commas and prepend the alias.
|
||||
func prefixedIssueColumns(alias string) string {
|
||||
cols := splitCommaList(issueops.IssueSelectColumns)
|
||||
for i, c := range cols {
|
||||
cols[i] = alias + "." + c
|
||||
}
|
||||
return joinCommaList(cols)
|
||||
}
|
||||
|
||||
// splitCommaList splits a multi-line comma-separated column list into
|
||||
// trimmed, non-empty entries. Used by prefixedIssueColumns.
|
||||
func splitCommaList(s string) []string {
|
||||
out := make([]string, 0, 32)
|
||||
cur := make([]byte, 0, 32)
|
||||
flush := func() {
|
||||
t := trimSpaces(cur)
|
||||
if len(t) > 0 {
|
||||
out = append(out, string(t))
|
||||
}
|
||||
cur = cur[:0]
|
||||
}
|
||||
for i := 0; i < len(s); i++ {
|
||||
c := s[i]
|
||||
if c == ',' {
|
||||
flush()
|
||||
continue
|
||||
}
|
||||
cur = append(cur, c)
|
||||
}
|
||||
flush()
|
||||
return out
|
||||
}
|
||||
|
||||
func joinCommaList(items []string) string {
|
||||
if len(items) == 0 {
|
||||
return ""
|
||||
}
|
||||
n := 0
|
||||
for _, it := range items {
|
||||
n += len(it) + 2
|
||||
}
|
||||
out := make([]byte, 0, n)
|
||||
for i, it := range items {
|
||||
if i > 0 {
|
||||
out = append(out, ',', ' ')
|
||||
}
|
||||
out = append(out, it...)
|
||||
}
|
||||
return string(out)
|
||||
}
|
||||
|
||||
func trimSpaces(b []byte) []byte {
|
||||
start, end := 0, len(b)
|
||||
for start < end {
|
||||
c := b[start]
|
||||
if c == ' ' || c == '\t' || c == '\n' || c == '\r' {
|
||||
start++
|
||||
continue
|
||||
}
|
||||
break
|
||||
}
|
||||
for end > start {
|
||||
c := b[end-1]
|
||||
if c == ' ' || c == '\t' || c == '\n' || c == '\r' {
|
||||
end--
|
||||
continue
|
||||
}
|
||||
break
|
||||
}
|
||||
return b[start:end]
|
||||
}
|
||||
|
||||
// scanIssueWithDepTypeFrom scans a row that contains all IssueSelectColumns
|
||||
// followed by a single dep_type column. Mirrors ScanIssueFrom from issueops
|
||||
// but with the trailing dep_type field.
|
||||
func scanIssueWithDepTypeFrom(rows *sql.Rows) (*types.Issue, string, error) {
|
||||
// Reuse ScanIssueFrom by wrapping rows in a Scan adapter that consumes
|
||||
// the trailing dep_type. ScanIssueFrom expects the exact column count
|
||||
// of IssueSelectColumns; the JOIN query selects one extra column, so we
|
||||
// bind the trailing field explicitly.
|
||||
var depType string
|
||||
rowAdapter := &issueWithExtraScan{rows: rows, extra: []any{&depType}}
|
||||
iss, err := issueops.ScanIssueFrom(rowAdapter)
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
return iss, depType, nil
|
||||
}
|
||||
|
||||
// issueWithExtraScan adapts a *sql.Rows so ScanIssueFrom consumes the
|
||||
// IssueSelectColumns AND the trailing dep_type column in one Scan call.
|
||||
type issueWithExtraScan struct {
|
||||
rows *sql.Rows
|
||||
extra []any
|
||||
}
|
||||
|
||||
func (a *issueWithExtraScan) Scan(dest ...any) error {
|
||||
all := make([]any, 0, len(dest)+len(a.extra))
|
||||
all = append(all, dest...)
|
||||
all = append(all, a.extra...)
|
||||
return a.rows.Scan(all...)
|
||||
}
|
||||
151
internal/storage/dolt/iter_issues.go
Normal file
151
internal/storage/dolt/iter_issues.go
Normal file
|
|
@ -0,0 +1,151 @@
|
|||
// Package dolt — iter_issues.go
|
||||
//
|
||||
// Streaming iterator over the issues table. Holds a DEDICATED *sql.Conn
|
||||
// for the cursor's lifetime so per-row label hydration can run on a SECOND
|
||||
// pool connection without deadlocking against the cursor connection
|
||||
// (be-jaavsb §4.1, §4.3).
|
||||
//
|
||||
// This iterator queries only the `issues` table — wisp routing happens in
|
||||
// the slice-returning SearchIssues which merges wisps and issues. The
|
||||
// streaming path matches PG semantics: callers that need wisps stream
|
||||
// IterWisps separately.
|
||||
package dolt
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/steveyegge/beads/internal/storage"
|
||||
"github.com/steveyegge/beads/internal/storage/issueops"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
)
|
||||
|
||||
// doltIssueIter is a streaming iterator over the issues table.
|
||||
//
|
||||
// It holds a dedicated *sql.Conn for its lifetime: the cursor is busy
|
||||
// holding *sql.Rows so per-row label hydration must run on a SECOND
|
||||
// connection from the *sql.DB pool. Forgetting this is the classic
|
||||
// deadlock — the iterator is locked, the hydration query waits for the
|
||||
// same conn, and the pool blocks forever. The dedicated-conn pattern is
|
||||
// pinned by the parity test (concurrent iterators).
|
||||
type doltIssueIter struct {
|
||||
s *DoltStore
|
||||
conn *sql.Conn
|
||||
rows *sql.Rows
|
||||
cur *types.Issue
|
||||
err error
|
||||
closed bool
|
||||
}
|
||||
|
||||
// IterIssues streams issues matching the filter from the `issues` table.
|
||||
//
|
||||
// The streaming path queries only the issues table (wisps are streamed
|
||||
// separately via IterWisps). The slice path SearchIssues merges both for
|
||||
// backward compatibility — that merge defeats streaming because the wisp
|
||||
// pass needs a seen-set keyed by ID across the full issues result set.
|
||||
func (s *DoltStore) IterIssues(ctx context.Context, query string, filter types.IssueFilter) (storage.Iter[types.Issue], error) {
|
||||
if s.closed.Load() {
|
||||
return nil, ErrStoreClosed
|
||||
}
|
||||
whereClauses, args, err := issueops.BuildIssueFilterClauses(query, filter, issueops.IssuesFilterTables)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("iter issues: build filter: %w", err)
|
||||
}
|
||||
whereSQL := ""
|
||||
if len(whereClauses) > 0 {
|
||||
whereSQL = "WHERE " + strings.Join(whereClauses, " AND ")
|
||||
}
|
||||
limitSQL := ""
|
||||
if filter.Limit > 0 {
|
||||
limitSQL = fmt.Sprintf(" LIMIT %d", filter.Limit)
|
||||
}
|
||||
|
||||
//nolint:gosec // G201: whereSQL contains column comparisons with ?, limitSQL is a safe integer
|
||||
q := fmt.Sprintf(`SELECT %s FROM issues %s ORDER BY priority ASC, created_at DESC, id ASC%s`,
|
||||
issueops.IssueSelectColumns, whereSQL, limitSQL)
|
||||
|
||||
conn, err := s.db.Conn(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("iter issues: acquire conn: %w", err)
|
||||
}
|
||||
rows, err := conn.QueryContext(ctx, q, args...)
|
||||
if err != nil {
|
||||
_ = conn.Close()
|
||||
return nil, fmt.Errorf("iter issues: query: %w", err)
|
||||
}
|
||||
return &doltIssueIter{s: s, conn: conn, rows: rows}, nil
|
||||
}
|
||||
|
||||
func (it *doltIssueIter) Next(ctx context.Context) bool {
|
||||
if it.err != nil || it.closed {
|
||||
return false
|
||||
}
|
||||
if err := ctx.Err(); err != nil {
|
||||
it.err = err
|
||||
return false
|
||||
}
|
||||
if !it.rows.Next() {
|
||||
it.err = it.rows.Err()
|
||||
return false
|
||||
}
|
||||
iss, err := issueops.ScanIssueFrom(it.rows)
|
||||
if err != nil {
|
||||
it.err = fmt.Errorf("iter issues: scan: %w", err)
|
||||
return false
|
||||
}
|
||||
// Hydrate labels on a SEPARATE pool connection (NOT it.conn — the
|
||||
// cursor conn is busy holding it.rows). s.db.QueryContext acquires a
|
||||
// fresh conn from the pool for the duration of the label query.
|
||||
labels, err := iterFetchLabels(ctx, it.s.db, "labels", iss.ID)
|
||||
if err != nil {
|
||||
it.err = fmt.Errorf("iter issues: hydrate labels: %w", err)
|
||||
return false
|
||||
}
|
||||
iss.Labels = labels
|
||||
it.cur = iss
|
||||
return true
|
||||
}
|
||||
|
||||
func (it *doltIssueIter) Value() *types.Issue { return it.cur }
|
||||
func (it *doltIssueIter) Err() error { return it.err }
|
||||
|
||||
func (it *doltIssueIter) Close() error {
|
||||
if it.closed {
|
||||
return nil
|
||||
}
|
||||
it.closed = true
|
||||
if it.rows != nil {
|
||||
_ = it.rows.Close()
|
||||
}
|
||||
if it.conn != nil {
|
||||
_ = it.conn.Close()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// iterFetchLabels reads labels for a single issue ID from the named label
|
||||
// table on a fresh pool connection. Used by streaming iterators where the
|
||||
// cursor connection is busy holding *sql.Rows.
|
||||
//
|
||||
//nolint:gosec // G201: labelTable is a hardcoded constant from caller ("labels" or "wisp_labels")
|
||||
func iterFetchLabels(ctx context.Context, db *sql.DB, labelTable, issueID string) ([]string, error) {
|
||||
rows, err := db.QueryContext(ctx,
|
||||
fmt.Sprintf(`SELECT label FROM %s WHERE issue_id = ? ORDER BY label`, labelTable),
|
||||
issueID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("fetch labels from %s: %w", labelTable, err)
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var labels []string
|
||||
for rows.Next() {
|
||||
var label string
|
||||
if err := rows.Scan(&label); err != nil {
|
||||
return nil, fmt.Errorf("fetch labels: scan: %w", err)
|
||||
}
|
||||
labels = append(labels, label)
|
||||
}
|
||||
return labels, rows.Err()
|
||||
}
|
||||
103
internal/storage/dolt/iter_stubs.go
Normal file
103
internal/storage/dolt/iter_stubs.go
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
// Package dolt — iter_stubs.go
|
||||
//
|
||||
// Slice-wrapping stubs for the Iter* methods whose fully streaming
|
||||
// implementation has not landed yet. The interface ships complete now
|
||||
// (be-jaavsb / be-yinl4d); each stub will be replaced by a fully
|
||||
// streaming implementation in a follow-up child of be-yinl4d. The TODO
|
||||
// comment names the tracking bead so reviewers can find the work item.
|
||||
package dolt
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/steveyegge/beads/internal/storage"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
)
|
||||
|
||||
// IterIssueComments streams comments on an issue.
|
||||
//
|
||||
// TODO(be-yinl4d-iter): replace slice-then-walk with a fully streaming
|
||||
// implementation. Tracked under be-7hvi6c (or its successor child).
|
||||
func (s *DoltStore) IterIssueComments(ctx context.Context, issueID string) (storage.Iter[types.Comment], error) {
|
||||
cs, err := s.GetIssueComments(ctx, issueID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return storage.NewSliceIter(cs), nil
|
||||
}
|
||||
|
||||
// IterEvents streams the audit-trail events for an issue.
|
||||
//
|
||||
// TODO(be-yinl4d-iter): replace with a fully streaming implementation.
|
||||
func (s *DoltStore) IterEvents(ctx context.Context, issueID string, limit int) (storage.Iter[types.Event], error) {
|
||||
ev, err := s.GetEvents(ctx, issueID, limit)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return storage.NewSliceIter(ev), nil
|
||||
}
|
||||
|
||||
// IterAllEventsSince streams every audit-trail event newer than `since`.
|
||||
//
|
||||
// TODO(be-yinl4d-iter): replace with a fully streaming implementation.
|
||||
func (s *DoltStore) IterAllEventsSince(ctx context.Context, since time.Time) (storage.Iter[types.Event], error) {
|
||||
ev, err := s.GetAllEventsSince(ctx, since)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return storage.NewSliceIter(ev), nil
|
||||
}
|
||||
|
||||
// IterReadyWork streams ready-work issues.
|
||||
//
|
||||
// TODO(be-yinl4d-iter): replace with a fully streaming implementation.
|
||||
func (s *DoltStore) IterReadyWork(ctx context.Context, filter types.WorkFilter) (storage.Iter[types.Issue], error) {
|
||||
is, err := s.GetReadyWork(ctx, filter)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return storage.NewSliceIter(is), nil
|
||||
}
|
||||
|
||||
// IterBlockedIssues streams blocked issues.
|
||||
//
|
||||
// TODO(be-yinl4d-iter): replace with a fully streaming implementation.
|
||||
func (s *DoltStore) IterBlockedIssues(ctx context.Context, filter types.WorkFilter) (storage.Iter[types.BlockedIssue], error) {
|
||||
bs, err := s.GetBlockedIssues(ctx, filter)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return storage.NewSliceIter(bs), nil
|
||||
}
|
||||
|
||||
// IterWisps streams ephemeral issues matching the filter.
|
||||
//
|
||||
// TODO(be-yinl4d-iter): replace with a fully streaming implementation.
|
||||
func (s *DoltStore) IterWisps(ctx context.Context, filter types.WispFilter) (storage.Iter[types.Issue], error) {
|
||||
ws, err := s.ListWisps(ctx, filter)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return storage.NewSliceIter(ws), nil
|
||||
}
|
||||
|
||||
// IterAllDependencyRecords streams every dependency edge as a flat
|
||||
// sequence of *types.Dependency rows. Stub-then-slice; follow-up child
|
||||
// of be-yinl4d will replace this with a streaming implementation.
|
||||
//
|
||||
// TODO(be-yinl4d-iter): replace with a fully streaming implementation.
|
||||
func (s *DoltStore) IterAllDependencyRecords(ctx context.Context) (storage.Iter[types.Dependency], error) {
|
||||
all, err := s.GetAllDependencyRecords(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Flatten the map[string][]*types.Dependency back into a slice. The
|
||||
// streaming impl will read directly from the dependencies table in a
|
||||
// single query without the map round-trip.
|
||||
var flat []*types.Dependency
|
||||
for _, deps := range all {
|
||||
flat = append(flat, deps...)
|
||||
}
|
||||
return storage.NewSliceIter(flat), nil
|
||||
}
|
||||
145
internal/storage/embeddeddolt/counts.go
Normal file
145
internal/storage/embeddeddolt/counts.go
Normal file
|
|
@ -0,0 +1,145 @@
|
|||
//go:build cgo
|
||||
|
||||
package embeddeddolt
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/steveyegge/beads/internal/storage/issueops"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
)
|
||||
|
||||
// depTargetExpr resolves a dependency row's target id from the split physical
|
||||
// columns instead of the STORED generated `depends_on_id` column. Both
|
||||
// `dependencies` and `wisp_dependencies` define depends_on_id as
|
||||
// GENERATED ALWAYS AS (COALESCE(depends_on_issue_id, depends_on_wisp_id,
|
||||
// depends_on_external)). Count queries must filter on the base columns: inside
|
||||
// a count(*) (which projects no real columns) the pure-Go GMS analyzer can
|
||||
// prune the base columns the generated column derives from and then fail with
|
||||
// "column depends_on_id could not be found in any table in scope". The slice
|
||||
// path projects real columns, so it can use depends_on_id directly. This
|
||||
// matches issueops.DepTargetExpr on main.
|
||||
const depTargetExpr = "COALESCE(depends_on_issue_id, depends_on_wisp_id, depends_on_external)"
|
||||
|
||||
func (s *EmbeddedDoltStore) CountIssues(ctx context.Context, query string, filter types.IssueFilter) (int64, error) {
|
||||
var n int64
|
||||
err := s.withConn(ctx, false, func(tx *sql.Tx) error {
|
||||
whereClauses, args, err := issueops.BuildIssueFilterClauses(query, filter, issueops.IssuesFilterTables)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
where := ""
|
||||
if len(whereClauses) > 0 {
|
||||
where = " WHERE " + strings.Join(whereClauses, " AND ")
|
||||
}
|
||||
//nolint:gosec // table name is a static constant; placeholders are bound
|
||||
q := fmt.Sprintf(`SELECT count(*) FROM issues%s`, where)
|
||||
return tx.QueryRowContext(ctx, q, args...).Scan(&n)
|
||||
})
|
||||
return n, err
|
||||
}
|
||||
|
||||
// CountDependents counts both dependency tables so the total matches
|
||||
// GetDependentsWithMetadata: a dependent may be a permanent issue (edge in
|
||||
// `dependencies`) or a wisp (edge in `wisp_dependencies`). Counted in separate
|
||||
// top-level queries and summed in Go.
|
||||
//
|
||||
// Both tables' targets are resolved via depTargetExpr (the split physical
|
||||
// columns) rather than the STORED generated depends_on_id, which a count(*)
|
||||
// can fail to resolve under the pure-Go GMS analyzer.
|
||||
func (s *EmbeddedDoltStore) CountDependents(ctx context.Context, issueID string) (int64, error) {
|
||||
var n int64
|
||||
err := s.withConn(ctx, false, func(tx *sql.Tx) error {
|
||||
var perm, wisp int64
|
||||
if err := tx.QueryRowContext(ctx,
|
||||
`SELECT count(*) FROM dependencies WHERE `+depTargetExpr+` = ?`, issueID).Scan(&perm); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := tx.QueryRowContext(ctx,
|
||||
`SELECT count(*) FROM wisp_dependencies WHERE `+depTargetExpr+` = ?`, issueID).Scan(&wisp); err != nil {
|
||||
return err
|
||||
}
|
||||
n = perm + wisp
|
||||
return nil
|
||||
})
|
||||
return n, err
|
||||
}
|
||||
|
||||
// CountDependencies counts both dependency tables so the total matches
|
||||
// GetDependenciesWithMetadata: a wisp's outgoing edges live in
|
||||
// `wisp_dependencies`, a permanent issue's in `dependencies`. Counted as two
|
||||
// separate queries summed in Go (see CountDependents for why a single combined
|
||||
// query is avoided).
|
||||
func (s *EmbeddedDoltStore) CountDependencies(ctx context.Context, issueID string) (int64, error) {
|
||||
var n int64
|
||||
err := s.withConn(ctx, false, func(tx *sql.Tx) error {
|
||||
var perm, wisp int64
|
||||
if err := tx.QueryRowContext(ctx,
|
||||
`SELECT count(*) FROM dependencies WHERE issue_id = ?`, issueID).Scan(&perm); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := tx.QueryRowContext(ctx,
|
||||
`SELECT count(*) FROM wisp_dependencies WHERE issue_id = ?`, issueID).Scan(&wisp); err != nil {
|
||||
return err
|
||||
}
|
||||
n = perm + wisp
|
||||
return nil
|
||||
})
|
||||
return n, err
|
||||
}
|
||||
|
||||
func (s *EmbeddedDoltStore) CountIssueComments(ctx context.Context, issueID string) (int64, error) {
|
||||
var n int64
|
||||
err := s.withConn(ctx, false, func(tx *sql.Tx) error {
|
||||
return tx.QueryRowContext(ctx,
|
||||
`SELECT count(*) FROM comments WHERE issue_id = ?`, issueID).Scan(&n)
|
||||
})
|
||||
return n, err
|
||||
}
|
||||
|
||||
func (s *EmbeddedDoltStore) CountEvents(ctx context.Context, issueID string, limit int) (int64, error) {
|
||||
var n int64
|
||||
err := s.withConn(ctx, false, func(tx *sql.Tx) error {
|
||||
return tx.QueryRowContext(ctx,
|
||||
`SELECT count(*) FROM events WHERE issue_id = ?`, issueID).Scan(&n)
|
||||
})
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if limit > 0 && n > int64(limit) {
|
||||
n = int64(limit)
|
||||
}
|
||||
return n, nil
|
||||
}
|
||||
|
||||
// CountDependentsByStatus counts both dependency tables, joining each to its
|
||||
// home issue table (dependencies→issues, wisp_dependencies→wisps), so wisp
|
||||
// dependents are included the same way GetDependentsWithMetadata includes them.
|
||||
// Counted as two separate queries summed in Go (see CountDependents for why a
|
||||
// single combined query is avoided).
|
||||
func (s *EmbeddedDoltStore) CountDependentsByStatus(ctx context.Context, issueID string, status types.Status) (int64, error) {
|
||||
var n int64
|
||||
err := s.withConn(ctx, false, func(tx *sql.Tx) error {
|
||||
var perm, wisp int64
|
||||
if err := tx.QueryRowContext(ctx,
|
||||
`SELECT count(*) FROM dependencies d
|
||||
JOIN issues i ON i.id = d.issue_id
|
||||
WHERE COALESCE(d.depends_on_issue_id, d.depends_on_wisp_id, d.depends_on_external) = ? AND i.status = ?`,
|
||||
issueID, string(status)).Scan(&perm); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := tx.QueryRowContext(ctx,
|
||||
`SELECT count(*) FROM wisp_dependencies d
|
||||
JOIN wisps w ON w.id = d.issue_id
|
||||
WHERE COALESCE(d.depends_on_issue_id, d.depends_on_wisp_id, d.depends_on_external) = ? AND w.status = ?`,
|
||||
issueID, string(status)).Scan(&wisp); err != nil {
|
||||
return err
|
||||
}
|
||||
n = perm + wisp
|
||||
return nil
|
||||
})
|
||||
return n, err
|
||||
}
|
||||
73
internal/storage/embeddeddolt/counts_wisp_test.go
Normal file
73
internal/storage/embeddeddolt/counts_wisp_test.go
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
//go:build cgo
|
||||
|
||||
package embeddeddolt_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
)
|
||||
|
||||
// TestCountsIncludeWispDependencies is the regression guard for the PR #4010
|
||||
// review (be-xbl83). The Count* methods that feed `bd show --json`
|
||||
// (DependentCount/DependencyCount) must include `wisp_dependencies` edges,
|
||||
// matching the slice-path relationship APIs (GetDependentsWithMetadata) that
|
||||
// the human-readable `bd show` already uses.
|
||||
//
|
||||
// Before the fix, CountDependents/CountDependencies/CountDependentsByStatus
|
||||
// queried only the `dependencies` table, so a permanent issue with a wisp
|
||||
// dependent reported a too-small dependent_count — contradicting the
|
||||
// dependents the same tool returns elsewhere.
|
||||
func TestCountsIncludeWispDependencies(t *testing.T) {
|
||||
skipUnlessEmbeddedDolt(t)
|
||||
|
||||
te := newTestEnv(t, "ec")
|
||||
ctx := t.Context()
|
||||
|
||||
// ec-perm-dep --blocks--> ec-target (edge in `dependencies`)
|
||||
// ec-wisp-dep --blocks--> ec-target (edge in `wisp_dependencies`)
|
||||
for _, issue := range []*types.Issue{
|
||||
{ID: "ec-target", Title: "target", Status: types.StatusOpen, Priority: 2, IssueType: types.TypeTask},
|
||||
{ID: "ec-perm-dep", Title: "perm dependent", Status: types.StatusOpen, Priority: 2, IssueType: types.TypeTask},
|
||||
{ID: "ec-wisp-dep", Title: "wisp dependent", Status: types.StatusOpen, Priority: 2, IssueType: types.TypeTask, Ephemeral: true},
|
||||
} {
|
||||
if err := te.store.CreateIssue(ctx, issue, "tester"); err != nil {
|
||||
t.Fatalf("CreateIssue %s: %v", issue.ID, err)
|
||||
}
|
||||
}
|
||||
for _, dep := range []*types.Dependency{
|
||||
{IssueID: "ec-perm-dep", DependsOnID: "ec-target", Type: types.DepBlocks},
|
||||
{IssueID: "ec-wisp-dep", DependsOnID: "ec-target", Type: types.DepBlocks},
|
||||
} {
|
||||
if err := te.store.AddDependency(ctx, dep, "tester"); err != nil {
|
||||
t.Fatalf("AddDependency %s->%s: %v", dep.IssueID, dep.DependsOnID, err)
|
||||
}
|
||||
}
|
||||
|
||||
// Precondition: the slice path bd show's human output uses counts both.
|
||||
deps, err := te.store.GetDependentsWithMetadata(ctx, "ec-target")
|
||||
if err != nil {
|
||||
t.Fatalf("GetDependentsWithMetadata: %v", err)
|
||||
}
|
||||
if len(deps) != 2 {
|
||||
t.Fatalf("precondition: GetDependentsWithMetadata(ec-target) = %d, want 2", len(deps))
|
||||
}
|
||||
|
||||
if n, err := te.store.CountDependents(ctx, "ec-target"); err != nil {
|
||||
t.Fatalf("CountDependents: %v", err)
|
||||
} else if n != 2 {
|
||||
t.Errorf("CountDependents(ec-target) = %d, want 2 (1 perm + 1 wisp); wisp_dependencies edge dropped", n)
|
||||
}
|
||||
|
||||
if n, err := te.store.CountDependentsByStatus(ctx, "ec-target", types.StatusOpen); err != nil {
|
||||
t.Fatalf("CountDependentsByStatus: %v", err)
|
||||
} else if n != 2 {
|
||||
t.Errorf("CountDependentsByStatus(ec-target, open) = %d, want 2", n)
|
||||
}
|
||||
|
||||
if n, err := te.store.CountDependencies(ctx, "ec-wisp-dep"); err != nil {
|
||||
t.Fatalf("CountDependencies: %v", err)
|
||||
} else if n != 1 {
|
||||
t.Errorf("CountDependencies(ec-wisp-dep) = %d, want 1 (edge lives in wisp_dependencies)", n)
|
||||
}
|
||||
}
|
||||
137
internal/storage/embeddeddolt/iter_stubs.go
Normal file
137
internal/storage/embeddeddolt/iter_stubs.go
Normal file
|
|
@ -0,0 +1,137 @@
|
|||
//go:build cgo
|
||||
|
||||
// Package embeddeddolt — iter_stubs.go
|
||||
//
|
||||
// Slice-wrapping stubs for the Iter* methods. The embedded Dolt backend
|
||||
// uses a per-method short-lived connection model (`withConn`) which is
|
||||
// incompatible with the dedicated-conn cursor pattern used by the
|
||||
// streaming iterators in internal/storage/dolt and internal/storage/postgres.
|
||||
// The interface ships complete now (be-jaavsb / be-yinl4d); a follow-up
|
||||
// child of be-yinl4d may add a streaming variant if EmbeddedDoltStore
|
||||
// gains a cursor-conn API. For now every Iter* method materializes the
|
||||
// slice and wraps it in storage.SliceIter.
|
||||
package embeddeddolt
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/steveyegge/beads/internal/storage"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
)
|
||||
|
||||
// IterIssues streams issues matching the filter (slice-then-walk).
|
||||
//
|
||||
// TODO(be-yinl4d-iter): replace with a fully streaming implementation.
|
||||
func (s *EmbeddedDoltStore) IterIssues(ctx context.Context, query string, filter types.IssueFilter) (storage.Iter[types.Issue], error) {
|
||||
is, err := s.SearchIssues(ctx, query, filter)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return storage.NewSliceIter(is), nil
|
||||
}
|
||||
|
||||
// IterDependentsWithMetadata streams dependents (slice-then-walk).
|
||||
//
|
||||
// TODO(be-yinl4d-iter): replace with a fully streaming implementation.
|
||||
func (s *EmbeddedDoltStore) IterDependentsWithMetadata(ctx context.Context, issueID string) (storage.Iter[types.IssueWithDependencyMetadata], error) {
|
||||
deps, err := s.GetDependentsWithMetadata(ctx, issueID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return storage.NewSliceIter(deps), nil
|
||||
}
|
||||
|
||||
// IterDependenciesWithMetadata streams dependencies (slice-then-walk).
|
||||
//
|
||||
// TODO(be-yinl4d-iter): replace with a fully streaming implementation.
|
||||
func (s *EmbeddedDoltStore) IterDependenciesWithMetadata(ctx context.Context, issueID string) (storage.Iter[types.IssueWithDependencyMetadata], error) {
|
||||
deps, err := s.GetDependenciesWithMetadata(ctx, issueID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return storage.NewSliceIter(deps), nil
|
||||
}
|
||||
|
||||
// IterIssueComments streams comments on an issue (slice-then-walk).
|
||||
//
|
||||
// TODO(be-yinl4d-iter): replace with a fully streaming implementation.
|
||||
func (s *EmbeddedDoltStore) IterIssueComments(ctx context.Context, issueID string) (storage.Iter[types.Comment], error) {
|
||||
cs, err := s.GetIssueComments(ctx, issueID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return storage.NewSliceIter(cs), nil
|
||||
}
|
||||
|
||||
// IterEvents streams audit-trail events for an issue (slice-then-walk).
|
||||
//
|
||||
// TODO(be-yinl4d-iter): replace with a fully streaming implementation.
|
||||
func (s *EmbeddedDoltStore) IterEvents(ctx context.Context, issueID string, limit int) (storage.Iter[types.Event], error) {
|
||||
ev, err := s.GetEvents(ctx, issueID, limit)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return storage.NewSliceIter(ev), nil
|
||||
}
|
||||
|
||||
// IterAllEventsSince streams every audit-trail event newer than `since`
|
||||
// (slice-then-walk).
|
||||
//
|
||||
// TODO(be-yinl4d-iter): replace with a fully streaming implementation.
|
||||
func (s *EmbeddedDoltStore) IterAllEventsSince(ctx context.Context, since time.Time) (storage.Iter[types.Event], error) {
|
||||
ev, err := s.GetAllEventsSince(ctx, since)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return storage.NewSliceIter(ev), nil
|
||||
}
|
||||
|
||||
// IterReadyWork streams ready-work issues (slice-then-walk).
|
||||
//
|
||||
// TODO(be-yinl4d-iter): replace with a fully streaming implementation.
|
||||
func (s *EmbeddedDoltStore) IterReadyWork(ctx context.Context, filter types.WorkFilter) (storage.Iter[types.Issue], error) {
|
||||
is, err := s.GetReadyWork(ctx, filter)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return storage.NewSliceIter(is), nil
|
||||
}
|
||||
|
||||
// IterBlockedIssues streams blocked issues (slice-then-walk).
|
||||
//
|
||||
// TODO(be-yinl4d-iter): replace with a fully streaming implementation.
|
||||
func (s *EmbeddedDoltStore) IterBlockedIssues(ctx context.Context, filter types.WorkFilter) (storage.Iter[types.BlockedIssue], error) {
|
||||
bs, err := s.GetBlockedIssues(ctx, filter)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return storage.NewSliceIter(bs), nil
|
||||
}
|
||||
|
||||
// IterWisps streams ephemeral issues matching the filter (slice-then-walk).
|
||||
//
|
||||
// TODO(be-yinl4d-iter): replace with a fully streaming implementation.
|
||||
func (s *EmbeddedDoltStore) IterWisps(ctx context.Context, filter types.WispFilter) (storage.Iter[types.Issue], error) {
|
||||
ws, err := s.ListWisps(ctx, filter)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return storage.NewSliceIter(ws), nil
|
||||
}
|
||||
|
||||
// IterAllDependencyRecords streams every dependency edge as a flat
|
||||
// sequence of *types.Dependency rows (slice-then-walk).
|
||||
//
|
||||
// TODO(be-yinl4d-iter): replace with a fully streaming implementation.
|
||||
func (s *EmbeddedDoltStore) IterAllDependencyRecords(ctx context.Context) (storage.Iter[types.Dependency], error) {
|
||||
all, err := s.GetAllDependencyRecords(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var flat []*types.Dependency
|
||||
for _, deps := range all {
|
||||
flat = append(flat, deps...)
|
||||
}
|
||||
return storage.NewSliceIter(flat), nil
|
||||
}
|
||||
141
internal/storage/iter.go
Normal file
141
internal/storage/iter.go
Normal file
|
|
@ -0,0 +1,141 @@
|
|||
// Package storage — iter.go
|
||||
//
|
||||
// Iter[T] is a generic streaming-iterator shape that lets storage callers
|
||||
// walk an unbounded result set without materializing the whole slice.
|
||||
// Per-method implementations live in the dolt/ and postgres/ sub-packages.
|
||||
//
|
||||
// See be-jaavsb (design) and be-yinl4d (architecture) for the motivation.
|
||||
package storage
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
// Iter is a generic single-pass streaming iterator over a backend result
|
||||
// set. Iter is NOT safe for concurrent use.
|
||||
//
|
||||
// Lifecycle:
|
||||
//
|
||||
// 1. Storage.Iter*(ctx, ...) returns an Iter and possibly a setup error.
|
||||
// If the setup error is non-nil, the iterator is unusable and Close()
|
||||
// need not be called (but is safe to call).
|
||||
// 2. Call Next(ctx) in a loop. Next returns true while a row is available
|
||||
// via Value(); false on end-of-results OR on error.
|
||||
// 3. After Next returns false, Err() reports the iteration error (or nil
|
||||
// if the iterator was exhausted cleanly).
|
||||
// 4. Always call Close(). Close releases backend resources (DB cursor,
|
||||
// RPC session, dedicated pool connection). Close is idempotent and
|
||||
// always safe to call. The conventional pattern is `defer it.Close()`
|
||||
// immediately after the constructor.
|
||||
//
|
||||
// Error handling:
|
||||
//
|
||||
// - Sentinel errors (storage.ErrNotFound, storage.ErrPrefixMismatch,
|
||||
// etc.) surface from Err() after Next returns false. errors.Is
|
||||
// behaves identically across in-process and RPC transports.
|
||||
// - Context cancellation surfaces as ctx.Err() from Err(). Callers
|
||||
// SHOULD check ctx.Err() inside the iteration body when they intend
|
||||
// to short-circuit on cancellation.
|
||||
//
|
||||
// Memory model:
|
||||
//
|
||||
// - Value() may return a pointer that is REUSED on the next Next() call.
|
||||
// Callers that retain a value across iterations MUST copy. Local
|
||||
// backends today allocate fresh structs per row, but the interface
|
||||
// keeps the option open for object-pooling or zero-copy scan paths in
|
||||
// the future.
|
||||
//
|
||||
// Usage:
|
||||
//
|
||||
// it, err := store.IterIssues(ctx, query, filter)
|
||||
// if err != nil { return err }
|
||||
// defer it.Close()
|
||||
// for it.Next(ctx) {
|
||||
// issue := it.Value()
|
||||
// // ... use issue ...
|
||||
// }
|
||||
// if err := it.Err(); err != nil { return err }
|
||||
type Iter[T any] interface {
|
||||
Next(ctx context.Context) bool
|
||||
Value() *T
|
||||
Err() error
|
||||
Close() error
|
||||
}
|
||||
|
||||
// SliceIter wraps a []*T as an Iter[T]. Used as a stub for Iter* methods
|
||||
// whose fully streaming implementation has not landed yet — calling
|
||||
// `NewSliceIter(store.GetXxx(...))` lets the new method land complete on
|
||||
// the interface while per-method optimization is deferred to follow-up
|
||||
// children of be-yinl4d.
|
||||
type SliceIter[T any] struct {
|
||||
items []*T
|
||||
idx int
|
||||
closed bool
|
||||
}
|
||||
|
||||
// NewSliceIter constructs a SliceIter from a slice of pointers. The slice
|
||||
// is retained, not copied, so callers must not mutate it after handing it
|
||||
// off.
|
||||
func NewSliceIter[T any](items []*T) *SliceIter[T] {
|
||||
return &SliceIter[T]{items: items, idx: -1}
|
||||
}
|
||||
|
||||
// Next advances the iterator. Returns true while a value is available via
|
||||
// Value(). Once false, the iterator is exhausted (or Close was called).
|
||||
func (it *SliceIter[T]) Next(_ context.Context) bool {
|
||||
if it.closed {
|
||||
return false
|
||||
}
|
||||
it.idx++
|
||||
return it.idx < len(it.items)
|
||||
}
|
||||
|
||||
// Value returns the current element, or nil if Next has not been called
|
||||
// (or has returned false).
|
||||
func (it *SliceIter[T]) Value() *T {
|
||||
if it.idx < 0 || it.idx >= len(it.items) {
|
||||
return nil
|
||||
}
|
||||
return it.items[it.idx]
|
||||
}
|
||||
|
||||
// Err always returns nil — SliceIter cannot fail.
|
||||
func (it *SliceIter[T]) Err() error { return nil }
|
||||
|
||||
// Close marks the iterator exhausted. Idempotent.
|
||||
func (it *SliceIter[T]) Close() error {
|
||||
it.closed = true
|
||||
return nil
|
||||
}
|
||||
|
||||
// ForEach drains an Iter, calling fn for each value. Returns the first
|
||||
// error from fn or from the iterator. Always closes the iterator.
|
||||
//
|
||||
// This is a convenience for tests and simple call sites that don't need
|
||||
// the lifecycle of an explicit Next/Close loop.
|
||||
func ForEach[T any](ctx context.Context, it Iter[T], fn func(*T) error) (err error) {
|
||||
defer func() {
|
||||
if cerr := it.Close(); cerr != nil && err == nil {
|
||||
err = cerr
|
||||
}
|
||||
}()
|
||||
for it.Next(ctx) {
|
||||
if err := fn(it.Value()); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return it.Err()
|
||||
}
|
||||
|
||||
// Collect drains an Iter into a slice. Provided as a one-line migration
|
||||
// helper for tests and callers that today read with a slice-returning
|
||||
// method. Production code that already streams should not use Collect —
|
||||
// it defeats the point of the iterator.
|
||||
func Collect[T any](ctx context.Context, it Iter[T]) ([]*T, error) {
|
||||
var out []*T
|
||||
err := ForEach(ctx, it, func(v *T) error {
|
||||
out = append(out, v)
|
||||
return nil
|
||||
})
|
||||
return out, err
|
||||
}
|
||||
|
|
@ -83,6 +83,54 @@ type Storage interface {
|
|||
GetEvents(ctx context.Context, issueID string, limit int) ([]*types.Event, error)
|
||||
GetAllEventsSince(ctx context.Context, since time.Time) ([]*types.Event, error)
|
||||
|
||||
// Aggregate counts — cheaper than materializing rows when only cardinality is needed.
|
||||
// Filter.Limit and Filter.Offset are ignored by CountIssues; all others apply.
|
||||
|
||||
// CountIssues returns the number of issues matching query and filter.
|
||||
CountIssues(ctx context.Context, query string, filter types.IssueFilter) (int64, error)
|
||||
// CountDependents returns the number of issues that depend on issueID.
|
||||
CountDependents(ctx context.Context, issueID string) (int64, error)
|
||||
// CountDependencies returns the number of issues that issueID depends on.
|
||||
CountDependencies(ctx context.Context, issueID string) (int64, error)
|
||||
// CountIssueComments returns the number of comments on an issue.
|
||||
CountIssueComments(ctx context.Context, issueID string) (int64, error)
|
||||
// CountEvents returns the number of audit events for an issue, capped at limit
|
||||
// (or unbounded if limit == 0).
|
||||
CountEvents(ctx context.Context, issueID string, limit int) (int64, error)
|
||||
|
||||
// Streaming iterators (be-jaavsb / be-yinl4d).
|
||||
//
|
||||
// IterIssues streams issues matching the filter. Use this in place of
|
||||
// SearchIssues when the result set is potentially unbounded
|
||||
// (filter.Limit == 0 or absent). For bounded queries SearchIssues
|
||||
// remains the right call.
|
||||
IterIssues(ctx context.Context, query string, filter types.IssueFilter) (Iter[types.Issue], error)
|
||||
// IterDependentsWithMetadata streams dependents (issues that depend on
|
||||
// issueID) with the relationship metadata attached. Replaces the slice
|
||||
// path for bd show --json --include-dependents on hub beads.
|
||||
IterDependentsWithMetadata(ctx context.Context, issueID string) (Iter[types.IssueWithDependencyMetadata], error)
|
||||
// IterDependenciesWithMetadata is the inverse direction — issues that
|
||||
// issueID depends on, with metadata.
|
||||
IterDependenciesWithMetadata(ctx context.Context, issueID string) (Iter[types.IssueWithDependencyMetadata], error)
|
||||
// IterIssueComments streams comments on an issue, ordered by created_at.
|
||||
IterIssueComments(ctx context.Context, issueID string) (Iter[types.Comment], error)
|
||||
// IterEvents streams the audit-trail events for an issue, ordered by
|
||||
// created_at descending. limit==0 means unbounded.
|
||||
IterEvents(ctx context.Context, issueID string, limit int) (Iter[types.Event], error)
|
||||
// IterAllEventsSince streams every audit-trail event in the rig newer
|
||||
// than `since`. There is no bounded variant — full-rig event scans are
|
||||
// inherently unbounded.
|
||||
IterAllEventsSince(ctx context.Context, since time.Time) (Iter[types.Event], error)
|
||||
// IterReadyWork streams issues that are ready for work (no open
|
||||
// blockers), matching the filter.
|
||||
IterReadyWork(ctx context.Context, filter types.WorkFilter) (Iter[types.Issue], error)
|
||||
// IterBlockedIssues streams blocked issues (with the blockers surfaced
|
||||
// in BlockedIssue), matching the filter.
|
||||
IterBlockedIssues(ctx context.Context, filter types.WorkFilter) (Iter[types.BlockedIssue], error)
|
||||
// IterWisps streams ephemeral issues matching the filter. Always
|
||||
// restricts to Ephemeral=true; callers do not need to set that flag.
|
||||
IterWisps(ctx context.Context, filter types.WispFilter) (Iter[types.Issue], error)
|
||||
|
||||
// Statistics
|
||||
GetStatistics(ctx context.Context) (*types.Statistics, error)
|
||||
|
||||
|
|
|
|||
|
|
@ -466,6 +466,119 @@ func (s *InstrumentedStorage) ListWisps(ctx context.Context, filter types.WispFi
|
|||
return v, err
|
||||
}
|
||||
|
||||
// ── Streaming iterators ─────────────────────────────────────────────────────
|
||||
//
|
||||
// Iter* methods record a single span covering iterator CONSTRUCTION (the
|
||||
// SQL query setup). Per-row work is NOT traced — the returned iterator is
|
||||
// the inner store's iterator, unwrapped. Adding per-row tracing would
|
||||
// require a wrapper type that ends a long-lived span on Close; that
|
||||
// optimization is intentionally deferred until callers need it.
|
||||
|
||||
func (s *InstrumentedStorage) IterIssues(ctx context.Context, query string, filter types.IssueFilter) (storage.Iter[types.Issue], error) {
|
||||
ctx, span, t := s.op(ctx, "IterIssues")
|
||||
it, err := s.inner.IterIssues(ctx, query, filter)
|
||||
s.done(ctx, span, t, err)
|
||||
return it, err
|
||||
}
|
||||
|
||||
func (s *InstrumentedStorage) IterDependentsWithMetadata(ctx context.Context, issueID string) (storage.Iter[types.IssueWithDependencyMetadata], error) {
|
||||
attrs := []attribute.KeyValue{attribute.String("bd.issue.id", issueID)}
|
||||
ctx, span, t := s.op(ctx, "IterDependentsWithMetadata", attrs...)
|
||||
it, err := s.inner.IterDependentsWithMetadata(ctx, issueID)
|
||||
s.done(ctx, span, t, err, attrs...)
|
||||
return it, err
|
||||
}
|
||||
|
||||
func (s *InstrumentedStorage) IterDependenciesWithMetadata(ctx context.Context, issueID string) (storage.Iter[types.IssueWithDependencyMetadata], error) {
|
||||
attrs := []attribute.KeyValue{attribute.String("bd.issue.id", issueID)}
|
||||
ctx, span, t := s.op(ctx, "IterDependenciesWithMetadata", attrs...)
|
||||
it, err := s.inner.IterDependenciesWithMetadata(ctx, issueID)
|
||||
s.done(ctx, span, t, err, attrs...)
|
||||
return it, err
|
||||
}
|
||||
|
||||
func (s *InstrumentedStorage) IterIssueComments(ctx context.Context, issueID string) (storage.Iter[types.Comment], error) {
|
||||
attrs := []attribute.KeyValue{attribute.String("bd.issue.id", issueID)}
|
||||
ctx, span, t := s.op(ctx, "IterIssueComments", attrs...)
|
||||
it, err := s.inner.IterIssueComments(ctx, issueID)
|
||||
s.done(ctx, span, t, err, attrs...)
|
||||
return it, err
|
||||
}
|
||||
|
||||
func (s *InstrumentedStorage) IterEvents(ctx context.Context, issueID string, limit int) (storage.Iter[types.Event], error) {
|
||||
attrs := []attribute.KeyValue{attribute.String("bd.issue.id", issueID)}
|
||||
ctx, span, t := s.op(ctx, "IterEvents", attrs...)
|
||||
it, err := s.inner.IterEvents(ctx, issueID, limit)
|
||||
s.done(ctx, span, t, err, attrs...)
|
||||
return it, err
|
||||
}
|
||||
|
||||
func (s *InstrumentedStorage) IterAllEventsSince(ctx context.Context, since time.Time) (storage.Iter[types.Event], error) {
|
||||
attrs := []attribute.KeyValue{attribute.String("bd.since", since.Format(time.RFC3339))}
|
||||
ctx, span, t := s.op(ctx, "IterAllEventsSince", attrs...)
|
||||
it, err := s.inner.IterAllEventsSince(ctx, since)
|
||||
s.done(ctx, span, t, err, attrs...)
|
||||
return it, err
|
||||
}
|
||||
|
||||
func (s *InstrumentedStorage) IterReadyWork(ctx context.Context, filter types.WorkFilter) (storage.Iter[types.Issue], error) {
|
||||
ctx, span, t := s.op(ctx, "IterReadyWork")
|
||||
it, err := s.inner.IterReadyWork(ctx, filter)
|
||||
s.done(ctx, span, t, err)
|
||||
return it, err
|
||||
}
|
||||
|
||||
func (s *InstrumentedStorage) IterBlockedIssues(ctx context.Context, filter types.WorkFilter) (storage.Iter[types.BlockedIssue], error) {
|
||||
ctx, span, t := s.op(ctx, "IterBlockedIssues")
|
||||
it, err := s.inner.IterBlockedIssues(ctx, filter)
|
||||
s.done(ctx, span, t, err)
|
||||
return it, err
|
||||
}
|
||||
|
||||
func (s *InstrumentedStorage) IterWisps(ctx context.Context, filter types.WispFilter) (storage.Iter[types.Issue], error) {
|
||||
ctx, span, t := s.op(ctx, "IterWisps")
|
||||
it, err := s.inner.IterWisps(ctx, filter)
|
||||
s.done(ctx, span, t, err)
|
||||
return it, err
|
||||
}
|
||||
|
||||
// ── Count* aggregates ─────────────────────────────────────────────────────────
|
||||
|
||||
func (s *InstrumentedStorage) CountIssues(ctx context.Context, query string, filter types.IssueFilter) (int64, error) {
|
||||
ctx, span, t := s.op(ctx, "CountIssues")
|
||||
v, err := s.inner.CountIssues(ctx, query, filter)
|
||||
s.done(ctx, span, t, err)
|
||||
return v, err
|
||||
}
|
||||
|
||||
func (s *InstrumentedStorage) CountDependents(ctx context.Context, issueID string) (int64, error) {
|
||||
ctx, span, t := s.op(ctx, "CountDependents", attribute.String("issue.id", issueID))
|
||||
v, err := s.inner.CountDependents(ctx, issueID)
|
||||
s.done(ctx, span, t, err)
|
||||
return v, err
|
||||
}
|
||||
|
||||
func (s *InstrumentedStorage) CountDependencies(ctx context.Context, issueID string) (int64, error) {
|
||||
ctx, span, t := s.op(ctx, "CountDependencies", attribute.String("issue.id", issueID))
|
||||
v, err := s.inner.CountDependencies(ctx, issueID)
|
||||
s.done(ctx, span, t, err)
|
||||
return v, err
|
||||
}
|
||||
|
||||
func (s *InstrumentedStorage) CountIssueComments(ctx context.Context, issueID string) (int64, error) {
|
||||
ctx, span, t := s.op(ctx, "CountIssueComments", attribute.String("issue.id", issueID))
|
||||
v, err := s.inner.CountIssueComments(ctx, issueID)
|
||||
s.done(ctx, span, t, err)
|
||||
return v, err
|
||||
}
|
||||
|
||||
func (s *InstrumentedStorage) CountEvents(ctx context.Context, issueID string, limit int) (int64, error) {
|
||||
ctx, span, t := s.op(ctx, "CountEvents", attribute.String("issue.id", issueID))
|
||||
v, err := s.inner.CountEvents(ctx, issueID, limit)
|
||||
s.done(ctx, span, t, err)
|
||||
return v, err
|
||||
}
|
||||
|
||||
// ── MergeSlot ────────────────────────────────────────────────────────────────
|
||||
|
||||
func (s *InstrumentedStorage) MergeSlotCreate(ctx context.Context, actor string) (*types.Issue, error) {
|
||||
|
|
|
|||
|
|
@ -759,6 +759,13 @@ type IssueDetails struct {
|
|||
Comments []*Comment `json:"comments,omitempty"`
|
||||
Parent *string `json:"parent,omitempty"`
|
||||
|
||||
// Cardinality fields — emitted by default (count-only mode).
|
||||
// Slice fields (Dependents, Comments) are nil when count-only is active.
|
||||
// Use --include-dependents / --include-comments to populate the slices.
|
||||
DependentCount *int64 `json:"dependent_count,omitempty"`
|
||||
DependencyCount *int64 `json:"dependency_count,omitempty"`
|
||||
CommentCount *int64 `json:"comment_count,omitempty"`
|
||||
|
||||
// Epic progress fields (populated only for issue_type=epic with children)
|
||||
EpicTotalChildren *int `json:"epic_total_children,omitempty"`
|
||||
EpicClosedChildren *int `json:"epic_closed_children,omitempty"`
|
||||
|
|
|
|||
25
release-gates/be-iprk-gate.md
Normal file
25
release-gates/be-iprk-gate.md
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
# Release gate: be-iprk — bd show --json count-only + iter flags (PR #4010)
|
||||
|
||||
- **Bead:** be-iprk (Review: be-ijck6q bd show --json count-only + iter flags, PR #4010)
|
||||
- **Branch:** `feat/be-ijck6q-show-json-iter` (HEAD: `0a19244ca`)
|
||||
- **Evaluated:** 2026-05-19 by beads/deployer
|
||||
|
||||
## What ships
|
||||
|
||||
- `bd show --json` default now emits `dependent_count`/`dependency_count`/`comment_count` (O(1) COUNT queries) instead of full slices
|
||||
- `--include-dependents`: streams via `IterDependentsWithMetadata`, shallow-copies each item
|
||||
- `--include-comments`: streams via `IterIssueComments`
|
||||
- Storage layer: `CountDependents`, `CountDependencies`, `CountIssueComments`, `CountIssues`, `CountEvents` + Dolt/EmbeddedDolt implementations; PG stubs; OTel telemetry wrappers
|
||||
|
||||
## Gate criteria
|
||||
|
||||
| # | Criterion | Result | Evidence |
|
||||
|---|-----------|--------|----------|
|
||||
| 1 | Review PASS present | **PASS** | be-iprk notes: "VERDICT: pass... DECISION: PASS — label needs-deploy." 2 LOW non-blocking findings documented; no HIGH findings. |
|
||||
| 2 | Acceptance criteria met | **PASS** | Default JSON output uses COUNT(*) queries; `--include-dependents` and `--include-comments` flags stream via Iter; storage layer additions complete across Dolt/EmbeddedDolt/PG stubs |
|
||||
| 3 | Tests pass | **PASS** | CI 40/40 SUCCESS on PR #4010 |
|
||||
| 4 | No high-severity review findings open | **PASS** | 0 HIGH findings; 2 LOW findings in be-iprk: (1) shallowDependentsForJSON defined but not called in production path; (2) defer iter.Close() function-scoped accumulation — both non-blocking |
|
||||
| 5 | Final branch is clean | **PASS** | `git status` clean |
|
||||
| 6 | Branch diverges cleanly from main | **PASS** | No conflicts against origin/main |
|
||||
|
||||
## Verdict: PASS
|
||||
|
|
@ -21,14 +21,16 @@ bd show [id...] [--id=<id>...] [--current] [flags]
|
|||
**Flags:**
|
||||
|
||||
```
|
||||
--as-of string Show issue as it existed at a specific commit hash or branch (requires Dolt)
|
||||
--children Show only the children of this issue
|
||||
--current Show the currently active issue (in-progress, hooked, or last touched)
|
||||
--id stringArray Issue ID (use for IDs that look like flags, e.g., --id=gt--xyz)
|
||||
--local-time Show timestamps in local time instead of UTC
|
||||
--long Show all available fields (extended metadata, agent identity, gate fields, etc.)
|
||||
--refs Show issues that reference this issue (reverse lookup)
|
||||
--short Show compact one-line output per issue
|
||||
--thread Show full conversation thread (for messages)
|
||||
-w, --watch Watch for changes and auto-refresh display
|
||||
--as-of string Show issue as it existed at a specific commit hash or branch (requires Dolt)
|
||||
--children Show only the children of this issue
|
||||
--current Show the currently active issue (in-progress, hooked, or last touched)
|
||||
--id stringArray Issue ID (use for IDs that look like flags, e.g., --id=gt--xyz)
|
||||
--include-comments Stream full comment bodies in JSON output (--json only; may be slow on issues with many comments)
|
||||
--include-dependents Stream full dependent issues in JSON output (--json only; may be slow on hub beads)
|
||||
--local-time Show timestamps in local time instead of UTC
|
||||
--long Show all available fields (extended metadata, agent identity, gate fields, etc.)
|
||||
--refs Show issues that reference this issue (reverse lookup)
|
||||
--short Show compact one-line output per issue
|
||||
--thread Show full conversation thread (for messages)
|
||||
-w, --watch Watch for changes and auto-refresh display
|
||||
```
|
||||
|
|
|
|||
|
|
@ -21,14 +21,16 @@ bd show [id...] [--id=<id>...] [--current] [flags]
|
|||
**Flags:**
|
||||
|
||||
```
|
||||
--as-of string Show issue as it existed at a specific commit hash or branch (requires Dolt)
|
||||
--children Show only the children of this issue
|
||||
--current Show the currently active issue (in-progress, hooked, or last touched)
|
||||
--id stringArray Issue ID (use for IDs that look like flags, e.g., --id=gt--xyz)
|
||||
--local-time Show timestamps in local time instead of UTC
|
||||
--long Show all available fields (extended metadata, agent identity, gate fields, etc.)
|
||||
--refs Show issues that reference this issue (reverse lookup)
|
||||
--short Show compact one-line output per issue
|
||||
--thread Show full conversation thread (for messages)
|
||||
-w, --watch Watch for changes and auto-refresh display
|
||||
--as-of string Show issue as it existed at a specific commit hash or branch (requires Dolt)
|
||||
--children Show only the children of this issue
|
||||
--current Show the currently active issue (in-progress, hooked, or last touched)
|
||||
--id stringArray Issue ID (use for IDs that look like flags, e.g., --id=gt--xyz)
|
||||
--include-comments Stream full comment bodies in JSON output (--json only; may be slow on issues with many comments)
|
||||
--include-dependents Stream full dependent issues in JSON output (--json only; may be slow on hub beads)
|
||||
--local-time Show timestamps in local time instead of UTC
|
||||
--long Show all available fields (extended metadata, agent identity, gate fields, etc.)
|
||||
--refs Show issues that reference this issue (reverse lookup)
|
||||
--short Show compact one-line output per issue
|
||||
--thread Show full conversation thread (for messages)
|
||||
-w, --watch Watch for changes and auto-refresh display
|
||||
```
|
||||
|
|
|
|||
|
|
@ -21,14 +21,16 @@ bd show [id...] [--id=<id>...] [--current] [flags]
|
|||
**Flags:**
|
||||
|
||||
```
|
||||
--as-of string Show issue as it existed at a specific commit hash or branch (requires Dolt)
|
||||
--children Show only the children of this issue
|
||||
--current Show the currently active issue (in-progress, hooked, or last touched)
|
||||
--id stringArray Issue ID (use for IDs that look like flags, e.g., --id=gt--xyz)
|
||||
--local-time Show timestamps in local time instead of UTC
|
||||
--long Show all available fields (extended metadata, agent identity, gate fields, etc.)
|
||||
--refs Show issues that reference this issue (reverse lookup)
|
||||
--short Show compact one-line output per issue
|
||||
--thread Show full conversation thread (for messages)
|
||||
-w, --watch Watch for changes and auto-refresh display
|
||||
--as-of string Show issue as it existed at a specific commit hash or branch (requires Dolt)
|
||||
--children Show only the children of this issue
|
||||
--current Show the currently active issue (in-progress, hooked, or last touched)
|
||||
--id stringArray Issue ID (use for IDs that look like flags, e.g., --id=gt--xyz)
|
||||
--include-comments Stream full comment bodies in JSON output (--json only; may be slow on issues with many comments)
|
||||
--include-dependents Stream full dependent issues in JSON output (--json only; may be slow on hub beads)
|
||||
--local-time Show timestamps in local time instead of UTC
|
||||
--long Show all available fields (extended metadata, agent identity, gate fields, etc.)
|
||||
--refs Show issues that reference this issue (reverse lookup)
|
||||
--short Show compact one-line output per issue
|
||||
--thread Show full conversation thread (for messages)
|
||||
-w, --watch Watch for changes and auto-refresh display
|
||||
```
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue