Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/fixed-15508-link-memo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Cache the dashboard tracker’s unfiltered issue closer once per issue and exclude the carrying PR per row, preserving correct sibling links without extra lookups. This defensively preserves correct links if merged PR rows are included; current open-only tracker behavior is unchanged ([#15495](https://github.com/hivecommons/hive/issues/15495)).
11 changes: 8 additions & 3 deletions src/pkg/dashboard/stage_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -2931,7 +2931,8 @@ type stageTrackerLinkInfo struct {
at time.Time
}

// stageTrackerLinkMemo memoises link lookups keyed by owner/repo#number.
// stageTrackerLinkMemo memoises link lookups keyed by owner/repo#issue.
// The cached closer is unfiltered; each carrying PR excludes itself below.
type stageTrackerLinkMemo struct {
mu sync.Mutex
m map[string]stageTrackerLinkInfo
Expand Down Expand Up @@ -3007,7 +3008,7 @@ func (s *Server) stageTrackerEnrichSoftLinks(items []StageTrackerItem, qualify f
in, hit := s.stageTrackerLinks.get(key, now)
if !hit && lookups < stageTrackerLinkLookups && ctx.Err() == nil {
lookups++
facts, err := s.deps.GHClient.IssueLinkState(ctx, owner, name, li.Number, pr.Number)
facts, err := s.deps.GHClient.IssueLinkState(ctx, owner, name, li.Number, 0)
in = stageTrackerLinkInfo{title: facts.Title, state: facts.State, stateReason: facts.StateReason, closedBy: facts.ClosedBy, pr: facts.IsPR, ok: err == nil}
// Running out of this rebuild's budget says nothing
// about the issue: leave it for the next rebuild.
Expand All @@ -3021,7 +3022,11 @@ func (s *Server) stageTrackerEnrichSoftLinks(items []StageTrackerItem, qualify f
if in.ok {
li.Title, li.State = in.title, in.state
if in.state == "closed" {
li.StateReason, li.ClosedBy = in.stateReason, in.closedBy
li.StateReason, li.ClosedBy = in.stateReason, 0
// Exclude the carrying PR per row, not in the shared lookup.
if in.closedBy != pr.Number {
li.ClosedBy = in.closedBy
}
}
}
}
Expand Down
60 changes: 60 additions & 0 deletions src/pkg/dashboard/stage_tracker_link_memo_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package dashboard

import (
"fmt"
"net/http"
"net/http/httptest"
"strings"
"sync/atomic"
"testing"
"time"

"github.com/hivecommons/hive/pkg/github"
)

func TestStageTrackerLinkMemoSharesLookupAndExcludesCarryingPR(t *testing.T) {
var gets, closerReads atomic.Int32
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method == http.MethodPost && strings.HasSuffix(r.URL.Path, "/graphql") {
closerReads.Add(1)
fmt.Fprint(w, `{"data":{"repository":{"issue":{"closedByPullRequestsReferences":{"nodes":[{"number":70,"merged":true,"mergedAt":"2026-10-27T12:00:00Z"}]}}}}}`)
return
}
gets.Add(1)
fmt.Fprint(w, `{"number":76,"title":"Delivered issue","state":"closed","state_reason":"completed"}`)
}))
defer ts.Close()
s := newTestServer()
s.deps = &Dependencies{GHClient: github.NewClientForTest(ts.URL, "hivecommons", []string{"hive"}, s.logger)}
qualify := func(string) string { return "hivecommons/hive" }
now := time.Date(2026, 10, 27, 18, 0, 0, 0, time.UTC)

// Merged PRs are not tracker rows today. Exercise both row orders so a
// future inclusion cannot let a row's exclusion poison its sibling's memo.
for _, order := range [][]int{{70, 90}, {90, 70}} {
s.stageTrackerLinks = stageTrackerLinkMemo{}
beforeGets, before := gets.Load(), closerReads.Load()
for rebuild := 0; rebuild < 2; rebuild++ {
var items []StageTrackerItem
for _, number := range order {
items = append(items, StageTrackerItem{Repo: "hive", Number: number, Kind: "pr", LinkedIssues: []StageTrackerLinkedIssue{{Number: 76}}})
}
s.stageTrackerEnrichSoftLinks(items, qualify, now.Add(time.Duration(rebuild)*time.Minute))
for _, item := range items {
want := 70
if item.Number == 70 {
want = 0
}
if got := item.LinkedIssues[0].ClosedBy; got != want {
t.Fatalf("order %v rebuild %d PR #%d: closer = %d, want %d", order, rebuild, item.Number, got, want)
}
}
}
if got := gets.Load() - beforeGets; got != 1 {
t.Fatalf("order %v: issues GETs = %d, want 1 shared across siblings and rebuilds", order, got)
}
if got := closerReads.Load() - before; got != 1 {
t.Fatalf("order %v: closer reads = %d, want 1 shared across siblings and rebuilds", order, got)
}
}
}
Loading