From f6f978d647e01e28bb8cf0592fff2e98cc203138 Mon Sep 17 00:00:00 2001 From: gitmoot-intern Date: Sun, 15 Nov 2026 06:56:44 +0100 Subject: [PATCH 1/3] =?UTF-8?q?feat(galaxy):=20range=20selector=20?= =?UTF-8?q?=E2=80=94=201=20month,=203=20months,=20all=20time=20(gitmoot/gi?= =?UTF-8?q?tmoot#2655)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit GET /api/graph?range=30d|90d|all; missing or unknown means 30d, so the default request is unchanged. DataSource.Graph takes a canonical GraphRange (CanonicalGraphRange). Graph gains an optional Truncated {shown,total} for a wide range the server capped. Web: a range select under the repo filter, same style; ?range= in the URL (replaceState, like the Runs ?reviewer= facet) so reload keeps it; the loading veil shows for a user-initiated load of a different range; a late response for a superseded selection is dropped; the repo list refills per range and keeps the current selection; a note says 'updated every few minutes' or 'newest N of M runs' when truncated. --- api.go | 8 ++-- api_test.go | 6 +-- datasource.go | 46 +++++++++++++++++-- fakefeed.go | 8 ++-- graph_range_test.go | 54 ++++++++++++++++++++++ web/dist/index.html | 109 ++++++++++++++++++++++++++++++++++++++------ 6 files changed, 202 insertions(+), 29 deletions(-) create mode 100644 graph_range_test.go diff --git a/api.go b/api.go index 6c333ab..00d3059 100644 --- a/api.go +++ b/api.go @@ -710,10 +710,12 @@ func (s *server) handleJob(w http.ResponseWriter, r *http.Request) { writeJSON(w, http.StatusOK, node) } -// handleGraph serves GET /api/graph -> Graph, the whole-history galaxy view. -// An optional ?repo= scopes the graph to a single repository. +// handleGraph serves GET /api/graph -> Graph, the galaxy view. An optional +// ?repo= scopes the graph to a single repository; ?range=30d|90d|all picks the +// time window, and anything else is the 30-day default. func (s *server) handleGraph(w http.ResponseWriter, r *http.Request) { - g, err := s.ds.Graph(r.Context(), r.URL.Query().Get("repo")) + q := r.URL.Query() + g, err := s.ds.Graph(r.Context(), q.Get("repo"), CanonicalGraphRange(q.Get("range"))) if err != nil { http.Error(w, err.Error(), statusForError(err)) return diff --git a/api_test.go b/api_test.go index a45d6a7..740cfaf 100644 --- a/api_test.go +++ b/api_test.go @@ -658,7 +658,7 @@ func TestHandleWorkflowClampsCursorsAndLimits(t *testing.T) { func TestFakeWorkflowContractAndPagination(t *testing.T) { t.Setenv("FAKEFEED_WORKFLOWS", "1") ds := NewFakeDataSource() - graph, err := ds.Graph(context.Background(), "") + graph, err := ds.Graph(context.Background(), "", GraphRange30d) if err != nil { t.Fatalf("Graph: %v", err) } @@ -739,7 +739,7 @@ func TestFakeGalaxyAgentRecordCoverage(t *testing.T) { byName[agent.Name] = agent } - graph, err := ds.Graph(context.Background(), "") + graph, err := ds.Graph(context.Background(), "", GraphRange30d) if err != nil { t.Fatalf("Graph: %v", err) } @@ -899,7 +899,7 @@ func TestWorkflowSummaryJSONContract(t *testing.T) { func TestFakeWorkflowDisabled(t *testing.T) { t.Setenv("FAKEFEED_WORKFLOWS", "0") ds := NewFakeDataSource() - graph, err := ds.Graph(context.Background(), "") + graph, err := ds.Graph(context.Background(), "", GraphRange30d) if err != nil { t.Fatalf("Graph: %v", err) } diff --git a/datasource.go b/datasource.go index 07aa180..31e85d4 100644 --- a/datasource.go +++ b/datasource.go @@ -127,12 +127,47 @@ type GraphLink struct { Kind string `json:"kind"` } -// Graph is the whole-history galaxy view: every job across every run, plus -// repo/agent hub nodes, unioned into one force-directed graph. +// Graph is the galaxy view: the runs created within a GraphRange across every +// root, plus repo/reviewer hub nodes, unioned into one force-directed graph. type Graph struct { Nodes []GraphNode `json:"nodes"` Links []GraphLink `json:"links"` Repos []string `json:"repos"` // distinct repos, for the filter + // Truncated is set when a wide range (90d/all) holds more runs than the UI + // can draw without freezing the tab: Nodes then carries the newest Shown of + // Total runs, while Repos still lists every repo in the range so a repo + // filter reaches its full history. Never set for the 30-day default. + Truncated *GraphTruncation `json:"truncated,omitempty"` +} + +// GraphTruncation reports a capped galaxy: Shown of Total runs are present. +type GraphTruncation struct { + Shown int `json:"shown"` + Total int `json:"total"` +} + +// GraphRange is the galaxy's time window: runs created within the last 30 or +// 90 days, or all of history. +type GraphRange string + +const ( + GraphRange30d GraphRange = "30d" + GraphRange90d GraphRange = "90d" + GraphRangeAll GraphRange = "all" +) + +// CanonicalGraphRange maps a ?range= value to a GraphRange. Anything missing or +// unknown is the 30-day default, so clients that never send ?range= keep +// today's view. +func CanonicalGraphRange(raw string) GraphRange { + switch GraphRange(raw) { + case GraphRange90d: + return GraphRange90d + case GraphRangeAll: + return GraphRangeAll + default: + return GraphRange30d + } } // WorkflowSummary is the aggregate header for one workflow label. State counts @@ -758,9 +793,10 @@ type DataSource interface { // summary plus config section. Unknown names return a not-found sentinel // (mapped to 404 by the API layer). Agent(ctx context.Context, name string) (AgentDetail, error) - // Graph returns the whole-history galaxy graph. Empty repo => all runs; a - // non-empty repo scopes to that repository's jobs (and their hubs). - Graph(ctx context.Context, repo string) (Graph, error) + // Graph returns the galaxy graph for the runs created within rng. Empty repo + // => all repos; a non-empty repo scopes to that repository's runs (and their + // hubs). rng is always canonical (see CanonicalGraphRange). + Graph(ctx context.Context, repo string, rng GraphRange) (Graph, error) // Charts returns the per-day time series plus top-agent/top-repo/totals // breakdowns for the Charts page. days selects the window: 7, 30 or 90; a // days of 0 means all history. Days is oldest->newest and zero-filled diff --git a/fakefeed.go b/fakefeed.go index b85b18f..29bf8e3 100644 --- a/fakefeed.go +++ b/fakefeed.go @@ -239,10 +239,10 @@ func (f *FakeDataSource) ChangeCursor(context.Context) (string, error) { return strconv.Itoa(f.step), nil } -// Graph implements DataSource. The fake feed has a single run, so the galaxy is -// that run's jobs plus a repo hub and per-agent hubs — enough to exercise the -// Galaxy view standalone. -func (f *FakeDataSource) Graph(ctx context.Context, repo string) (Graph, error) { +// Graph implements DataSource. The fake feed has a single current run, so every +// range returns the same graph: that run's runs plus a repo hub and per-reviewer +// hubs — enough to exercise the Galaxy view standalone. +func (f *FakeDataSource) Graph(ctx context.Context, repo string, rng GraphRange) (Graph, error) { f.mu.Lock() nodes := f.cloneNodesLocked() workflowsEnabled := f.workflowsEnabled diff --git a/graph_range_test.go b/graph_range_test.go new file mode 100644 index 0000000..3953820 --- /dev/null +++ b/graph_range_test.go @@ -0,0 +1,54 @@ +package dashboard + +import ( + "context" + "net/http" + "net/http/httptest" + "testing" +) + +// rangeRecordingDataSource records the range /api/graph hands to Graph. +type rangeRecordingDataSource struct { + DataSource + repo string + rng GraphRange +} + +func (r *rangeRecordingDataSource) Graph(ctx context.Context, repo string, rng GraphRange) (Graph, error) { + r.repo, r.rng = repo, rng + return r.DataSource.Graph(ctx, repo, rng) +} + +// /api/graph passes a canonical range to the DataSource: the three known values +// through, and anything else (missing, unknown, wrong case) as the 30-day +// default, so a client that never sends ?range= gets today's view. +func TestGraphRangeReachesDataSourceCanonical(t *testing.T) { + ds := &rangeRecordingDataSource{DataSource: NewFakeDataSource()} + handler := Serve(ds) + for target, want := range map[string]GraphRange{ + "/api/graph": GraphRange30d, + "/api/graph?range=30d": GraphRange30d, + "/api/graph?range=90d": GraphRange90d, + "/api/graph?range=all": GraphRangeAll, + "/api/graph?range=ALL": GraphRange30d, + "/api/graph?range=365d": GraphRange30d, + "/api/graph?range=": GraphRange30d, + "/api/graph?repo=a/b&range=all": GraphRangeAll, + "/api/graph?range=90d&range=all": GraphRange90d, + } { + ds.rng = "" + rec := httptest.NewRecorder() + handler.ServeHTTP(rec, httptest.NewRequest(http.MethodGet, target, nil)) + if rec.Code != http.StatusOK { + t.Fatalf("GET %s = %d: %s", target, rec.Code, rec.Body.String()) + } + if ds.rng != want { + t.Fatalf("GET %s passed range %q, want %q", target, ds.rng, want) + } + } + rec := httptest.NewRecorder() + handler.ServeHTTP(rec, httptest.NewRequest(http.MethodGet, "/api/graph?repo=a/b&range=all", nil)) + if ds.repo != "a/b" { + t.Fatalf("repo = %q, want a/b alongside the range", ds.repo) + } +} diff --git a/web/dist/index.html b/web/dist/index.html index 47a2ec1..7da1a22 100644 --- a/web/dist/index.html +++ b/web/dist/index.html @@ -203,6 +203,7 @@ const r = this._parseRoute(location.pathname, location.search); this.state.view = r.view; if (r.view === 'jobs' && r.agent) this._jobsFacetAgent = r.agent; + if (r.view === 'galaxy') this._galaxyRange = r.range || '30d'; if (r.view === 'agents' && r.agent) this._pendingAgentDetail = r.agent; if (r.view === 'workflows') this._pendingWorkflowLabel = r.name || null; // Normalize unknown paths to '/' (Overview). Also tidy a non-canonical known @@ -210,7 +211,7 @@ if (r.unknown) { try { history.replaceState(null, '', '/'); } catch (e) {} } else { - const canon = this._routeUrl(r.view, { agent: r.agent, name: r.name }); + const canon = this._routeUrl(r.view, { agent: r.agent, name: r.name, range: r.range }); if ((location.pathname + location.search) !== canon) { try { history.replaceState(null, '', canon); } catch (e) {} } @@ -231,7 +232,7 @@ if (p.length > 1) p = p.replace(/\/+$/, '') || '/'; // drop trailing slash(es) if (p === '/' || p === '') return { view: 'overview' }; if (p === '/prs' || p === '/tasks') return { view: 'tasks' }; - if (p === '/galaxy') return { view: 'galaxy' }; + if (p === '/galaxy') { const rg = this._routeQueryRange(search); return rg === '30d' ? { view: 'galaxy' } : { view: 'galaxy', range: rg }; } if (p === '/charts') return { view: 'charts' }; if (p === '/health') return { view: 'health' }; if (p === '/config') return { view: 'config' }; @@ -277,7 +278,7 @@ switch (view) { case 'overview': return '/'; case 'tasks': return '/prs'; - case 'galaxy': return '/galaxy'; + case 'galaxy': return opts.range && opts.range !== '30d' ? '/galaxy?range=' + opts.range : '/galaxy'; case 'jobs': return opts.agent ? '/runs?reviewer=' + encodeURIComponent(opts.agent) : '/runs'; case 'workflows': return opts.name ? '/campaigns/' + encodeURIComponent(opts.name) : '/campaigns'; case 'agents': return opts.agent ? '/reviewers/' + encodeURIComponent(opts.agent) : '/reviewers'; @@ -353,6 +354,12 @@ } else if (r.view === 'jobs') { this._jobsFacetAgent = r.agent || ''; if (this._jobsRoot) this.renderJobs(false); + } else if (r.view === 'galaxy') { + const rg = r.range || '30d'; + if (rg !== (this._galaxyRange || '30d')) { + this._galaxyRange = rg; + if (this._galaxyRoot) { this._syncGalaxyRangeSelect(); this.fetchGalaxy(this._galaxyRepo || ''); } + } } if (this.state.view !== r.view) this.setState({ view: r.view }); } finally { @@ -767,7 +774,7 @@ // ============================================================ showOverview = () => { this.setState({ view: 'overview' }); this._navRoute('overview'); }; showTasks = () => { this.setState({ view: 'tasks' }); this._navRoute('tasks'); }; - showGalaxy = () => { this.setState({ view: 'galaxy' }); this._navRoute('galaxy'); }; + showGalaxy = () => { this.setState({ view: 'galaxy' }); this._navRoute('galaxy', { range: this._galaxyRange }); }; showWorkflows = () => { this._workflowLabel = ''; this._pendingWorkflowLabel = null; @@ -1334,8 +1341,12 @@ "#galaxy-root #g-count b{color:#7dcfff;font-weight:500}", "#galaxy-root #g-filterWrap{top:18px;right:18px;padding:10px 12px}", "#galaxy-root #g-filterWrap label{display:block;font-family:'JetBrains Mono',monospace;font-size:9.5px;text-transform:uppercase;letter-spacing:1.2px;color:#7f86ad;margin-bottom:6px}", - "#galaxy-root #g-repoFilter{appearance:none;-webkit-appearance:none;background:rgba(7,8,15,.85);color:#c8cce6;border:1px solid rgba(125,207,255,.18);border-radius:8px;font-family:'JetBrains Mono',monospace;font-size:12px;padding:7px 30px 7px 11px;min-width:210px;cursor:pointer;outline:none;background-image:url(\"data:image/svg+xml;utf8,\");background-repeat:no-repeat;background-position:right 11px center}", - "#galaxy-root #g-repoFilter:hover{border-color:rgba(125,207,255,.4)}", + "#galaxy-root #g-repoFilter,#galaxy-root #g-rangeFilter{appearance:none;-webkit-appearance:none;background:rgba(7,8,15,.85);color:#c8cce6;border:1px solid rgba(125,207,255,.18);border-radius:8px;font-family:'JetBrains Mono',monospace;font-size:12px;padding:7px 30px 7px 11px;min-width:210px;cursor:pointer;outline:none;background-image:url(\"data:image/svg+xml;utf8,\");background-repeat:no-repeat;background-position:right 11px center}", + "#galaxy-root #g-repoFilter:hover,#galaxy-root #g-rangeFilter:hover{border-color:rgba(125,207,255,.4)}", + "#galaxy-root #g-rangeFilter{min-width:0;width:100%}", + "#galaxy-root #g-filterWrap .g-field+.g-field{margin-top:10px}", + "#galaxy-root #g-rangeNote{font-family:'JetBrains Mono',monospace;font-size:10px;color:#7f86ad;margin-top:6px;max-width:210px;line-height:1.5}", + "#galaxy-root #g-rangeNote:empty{display:none}", "#galaxy-root #g-legend{bottom:18px;left:18px;padding:13px 15px;max-width:230px}", "#galaxy-root #g-legend .grp{margin-bottom:11px}", "#galaxy-root #g-legend .grp:last-child{margin-bottom:0}", @@ -1423,8 +1434,15 @@ '
showing 0 nodes / 0 links
', '', '
', - ' ', - ' ', + '
', + ' ', + ' ', + '
', + '
', + ' ', + ' ', + '
', + '
', '
', '
', '
nodes
', @@ -1446,6 +1464,16 @@ this._galaxyGraphEl = root.querySelector('#g-graph'); const sel = root.querySelector('#g-repoFilter'); sel.addEventListener('change', () => { this._galaxyRepo = sel.value; this.fetchGalaxy(sel.value); }); + const rangeSel = root.querySelector('#g-rangeFilter'); + rangeSel.value = this._galaxyRange || '30d'; + // A range change keeps the repo filter and replaces (not pushes) the URL, like + // the Runs page's ?reviewer= facet, so reload keeps the choice without + // stacking history. + rangeSel.addEventListener('change', () => { + this._galaxyRange = rangeSel.value; + this._navRoute('galaxy', { range: this._galaxyRange }, true); + this.fetchGalaxy(this._galaxyRepo || ''); + }); this._galaxyKeydown = (e) => { if (e.key === 'Escape' && this.state.view === 'galaxy' && this._galaxyDetailEl) this.closeGalaxyDetail(); }; @@ -1887,32 +1915,85 @@ } catch (e) {} } + // ?range= on /galaxy: 90d or all; anything else is the 30-day default, the same + // rule the server applies, so the URL and the request always agree. + _routeQueryRange(search) { + const s = (search || '').replace(/^\?/, ''); + const parts = s ? s.split('&') : []; + for (let i = 0; i < parts.length; i++) { + const eq = parts[i].indexOf('='); + if ((eq >= 0 ? parts[i].slice(0, eq) : parts[i]) === 'range') { + const v = eq >= 0 ? parts[i].slice(eq + 1) : ''; + return v === '90d' || v === 'all' ? v : '30d'; + } + } + return '30d'; + } + + _syncGalaxyRangeSelect() { + const rs = this._galaxyRoot && this._galaxyRoot.querySelector('#g-rangeFilter'); + if (rs) rs.value = this._galaxyRange || '30d'; + } + fetchGalaxy(repo, isPoll) { - const url = '/api/graph' + (repo ? '?repo=' + encodeURIComponent(repo) : ''); + const range = this._galaxyRange || '30d'; + const params = []; + if (repo) params.push('repo=' + encodeURIComponent(repo)); + if (range !== '30d') params.push('range=' + range); + const url = '/api/graph' + (params.length ? '?' + params.join('&') : ''); + // A user-initiated load (not a poll) of a different repo/range shows the loading + // veil; 3 months and all time can take a few seconds cold. A late answer for a + // superseded selection is dropped, so a slow all-time load cannot overwrite a + // newer 1-month view. + const key = repo + '|' + range; + this._galaxyWant = key; + const l0 = this._galaxyRoot.querySelector('#g-loading'); + if (!isPoll && l0 && key !== this._galaxyShown) { + l0.textContent = range === '30d' ? 'summoning the galaxy…' : 'summoning ' + (range === 'all' ? 'all of history' : 'three months') + '…'; + l0.style.display = 'flex'; l0.classList.remove('hidden'); + } fetch(url, { cache: 'no-store' }) .then(r => r.ok ? r.json() : Promise.reject(new Error('HTTP ' + r.status))) .then(json => { + if (this._galaxyWant !== key) return; this._galaxyRaw = json || { nodes: [], links: [], repos: [] }; - if (!this._galaxyFilterFilled) this.fillGalaxyFilter(this._galaxyRaw.repos || []); + // The repo list depends on the range; refill it when the range changes, + // keeping the current selection (re-added if it fell outside the range). + if (!this._galaxyFilterFilled || this._galaxyFilterRange !== range) this.fillGalaxyFilter(this._galaxyRaw.repos || [], range); + this._galaxyShown = key; + // Wide ranges: say when the server drew only the newest runs (and how to + // see a repo's whole history), else that they refresh every few minutes. + const note = this._galaxyRoot.querySelector('#g-rangeNote'); + if (note) { + const tr = this._galaxyRaw.truncated; + note.textContent = tr ? 'newest ' + tr.shown.toLocaleString() + ' of ' + tr.total.toLocaleString() + ' runs · pick a repository for its full history' + : (range !== '30d' ? 'updated every few minutes' : ''); + } this.renderGalaxy(isPoll); const l = this._galaxyRoot.querySelector('#g-loading'); - if (l) { l.classList.add('hidden'); setTimeout(() => { l.style.display = 'none'; }, 600); } + if (l) { l.classList.add('hidden'); setTimeout(() => { if (this._galaxyWant === key) l.style.display = 'none'; }, 600); } }) .catch(err => { - if (isPoll) return; // keep the current galaxy on a transient poll failure + if (isPoll || this._galaxyWant !== key) return; // keep the current galaxy on a transient poll failure const l = this._galaxyRoot.querySelector('#g-loading'); if (l) { l.classList.remove('hidden'); l.style.display = 'flex'; l.textContent = 'could not load /api/graph (' + err.message + ')'; } }); } - fillGalaxyFilter(repos) { + fillGalaxyFilter(repos, range) { const sel = this._galaxyRoot.querySelector('#g-repoFilter'); - (repos || []).forEach(rp => { + const keep = sel.value; + while (sel.options.length > 1) sel.remove(1); + const list = (repos || []).slice(); + if (keep && list.indexOf(keep) < 0) list.push(keep); + list.forEach(rp => { const o = document.createElement('option'); o.value = rp; o.textContent = rp.split('/').pop() + ' · ' + rp; sel.appendChild(o); }); + sel.value = keep; this._galaxyFilterFilled = true; + this._galaxyFilterRange = range || '30d'; } renderGalaxy(isPoll) { From 8f8559cfb51ea7396408fe4fd55f5590807e8ffb Mon Sep 17 00:00:00 2001 From: gitmoot-intern Date: Sun, 15 Nov 2026 07:13:29 +0100 Subject: [PATCH 2/3] fix(galaxy): cap the filter chip width so a long repo name cannot stretch it (gitmoot/gitmoot#2655) --- web/dist/index.html | 2 ++ 1 file changed, 2 insertions(+) diff --git a/web/dist/index.html b/web/dist/index.html index 7da1a22..2bbbbd8 100644 --- a/web/dist/index.html +++ b/web/dist/index.html @@ -1344,6 +1344,8 @@ "#galaxy-root #g-repoFilter,#galaxy-root #g-rangeFilter{appearance:none;-webkit-appearance:none;background:rgba(7,8,15,.85);color:#c8cce6;border:1px solid rgba(125,207,255,.18);border-radius:8px;font-family:'JetBrains Mono',monospace;font-size:12px;padding:7px 30px 7px 11px;min-width:210px;cursor:pointer;outline:none;background-image:url(\"data:image/svg+xml;utf8,\");background-repeat:no-repeat;background-position:right 11px center}", "#galaxy-root #g-repoFilter:hover,#galaxy-root #g-rangeFilter:hover{border-color:rgba(125,207,255,.4)}", "#galaxy-root #g-rangeFilter{min-width:0;width:100%}", + "#galaxy-root #g-repoFilter{width:100%;max-width:260px;text-overflow:ellipsis}", + "#galaxy-root #g-filterWrap{max-width:284px}", "#galaxy-root #g-filterWrap .g-field+.g-field{margin-top:10px}", "#galaxy-root #g-rangeNote{font-family:'JetBrains Mono',monospace;font-size:10px;color:#7f86ad;margin-top:6px;max-width:210px;line-height:1.5}", "#galaxy-root #g-rangeNote:empty{display:none}", From 4d6288504121e9b653f721ae4ff63f57c19d0c5a Mon Sep 17 00:00:00 2001 From: gitmoot-intern Date: Sun, 15 Nov 2026 07:28:03 +0100 Subject: [PATCH 3/3] fix(galaxy): only the newest graph request touches the page; decode ?range= (gitmoot/gitmoot#2655 review) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Each fetch takes a sequence number; success, failure and the loading-veil cleanup act only for the newest, so A → B → A can no longer let the first A's late response overwrite the second, nor a superseded failure show an error after its replacement succeeded. A poll is skipped while a request is in flight. ?range= is read with URLSearchParams, so encoded values such as range=%61ll agree with the server's decoded query. --- web/dist/index.html | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/web/dist/index.html b/web/dist/index.html index 2bbbbd8..92cf552 100644 --- a/web/dist/index.html +++ b/web/dist/index.html @@ -1920,16 +1920,9 @@ // ?range= on /galaxy: 90d or all; anything else is the 30-day default, the same // rule the server applies, so the URL and the request always agree. _routeQueryRange(search) { - const s = (search || '').replace(/^\?/, ''); - const parts = s ? s.split('&') : []; - for (let i = 0; i < parts.length; i++) { - const eq = parts[i].indexOf('='); - if ((eq >= 0 ? parts[i].slice(0, eq) : parts[i]) === 'range') { - const v = eq >= 0 ? parts[i].slice(eq + 1) : ''; - return v === '90d' || v === 'all' ? v : '30d'; - } - } - return '30d'; + let v = null; + try { v = new URLSearchParams(search || '').get('range'); } catch (e) { v = null; } + return v === '90d' || v === 'all' ? v : '30d'; } _syncGalaxyRangeSelect() { @@ -1944,11 +1937,18 @@ if (range !== '30d') params.push('range=' + range); const url = '/api/graph' + (params.length ? '?' + params.join('&') : ''); // A user-initiated load (not a poll) of a different repo/range shows the loading - // veil; 3 months and all time can take a few seconds cold. A late answer for a - // superseded selection is dropped, so a slow all-time load cannot overwrite a - // newer 1-month view. + // veil; 3 months and all time can take a few seconds cold. Every request takes a + // new sequence number and only the newest may touch the page, so a superseded + // request (including one for the same selection after A → B → A) can neither + // overwrite newer data nor show an error after a newer request succeeded. A poll + // is skipped while a request is still in flight, so it never supersedes a + // user's load and wide ranges don't pile up. + if (isPoll && this._galaxyInFlight) return; const key = repo + '|' + range; - this._galaxyWant = key; + const seq = (this._galaxySeq || 0) + 1; + this._galaxySeq = seq; + this._galaxyInFlight = true; + const current = () => this._galaxySeq === seq; const l0 = this._galaxyRoot.querySelector('#g-loading'); if (!isPoll && l0 && key !== this._galaxyShown) { l0.textContent = range === '30d' ? 'summoning the galaxy…' : 'summoning ' + (range === 'all' ? 'all of history' : 'three months') + '…'; @@ -1957,7 +1957,8 @@ fetch(url, { cache: 'no-store' }) .then(r => r.ok ? r.json() : Promise.reject(new Error('HTTP ' + r.status))) .then(json => { - if (this._galaxyWant !== key) return; + if (!current()) return; + this._galaxyInFlight = false; this._galaxyRaw = json || { nodes: [], links: [], repos: [] }; // The repo list depends on the range; refill it when the range changes, // keeping the current selection (re-added if it fell outside the range). @@ -1973,10 +1974,12 @@ } this.renderGalaxy(isPoll); const l = this._galaxyRoot.querySelector('#g-loading'); - if (l) { l.classList.add('hidden'); setTimeout(() => { if (this._galaxyWant === key) l.style.display = 'none'; }, 600); } + if (l) { l.classList.add('hidden'); setTimeout(() => { if (current()) l.style.display = 'none'; }, 600); } }) .catch(err => { - if (isPoll || this._galaxyWant !== key) return; // keep the current galaxy on a transient poll failure + if (!current()) return; + this._galaxyInFlight = false; + if (isPoll) return; // keep the current galaxy on a transient poll failure const l = this._galaxyRoot.querySelector('#g-loading'); if (l) { l.classList.remove('hidden'); l.style.display = 'flex'; l.textContent = 'could not load /api/graph (' + err.message + ')'; } });