diff --git a/internal/web/admin_mirror.go b/internal/web/admin_mirror.go index 3ef1eee..358b375 100644 --- a/internal/web/admin_mirror.go +++ b/internal/web/admin_mirror.go @@ -103,6 +103,8 @@ type adminMirrorData struct { Addr string Base string Rows []mirrorRow + // Groups are the same rows under their model. + Groups []mirrorGroup Fetching int Present int @@ -445,12 +447,57 @@ func (p *AccountPages) renderMirror(w http.ResponseWriter, r *http.Request, return a.File < b.File }) + d.Groups = groupByModel(d.Rows) + if d.Fetching > 0 { d.RefreshSec = 5 } render(w, "admin_mirror", d) } +// mirrorGroup is every version the mirror holds of one model. +type mirrorGroup struct { + Model string + Rows []mirrorRow + // Bytes is what the versions take on disk, downloads so far included. + Bytes int64 + Fetching, Failed int + InUse bool +} + +// groupByModel gathers rows under their model, in the order the rows are +// already in: a model downloading or failed comes first because its first row +// does, and its versions stay in that order beneath it. +// +// Grouped because a model is what somebody looks for. Sorted by state alone, +// three versions of one model were three rows scattered down the table, and +// "which versions of this do we have" meant reading all of it. +func groupByModel(rows []mirrorRow) []mirrorGroup { + var out []mirrorGroup + at := map[string]int{} + for _, r := range rows { + i, ok := at[r.Model] + if !ok { + i = len(out) + at[r.Model] = i + out = append(out, mirrorGroup{Model: r.Model}) + } + g := &out[i] + g.Rows = append(g.Rows, r) + g.Bytes += r.BytesDone + switch r.State { + case mirror.Fetching: + g.Fetching++ + case mirror.Failed: + g.Failed++ + } + if len(r.UsedBy) > 0 { + g.InUse = true + } + } + return out +} + func mirrorRank(s mirror.State) int { switch s { case mirror.Fetching: diff --git a/internal/web/admin_mirror_test.go b/internal/web/admin_mirror_test.go index 2962fa8..ba4e7df 100644 --- a/internal/web/admin_mirror_test.go +++ b/internal/web/admin_mirror_test.go @@ -600,3 +600,30 @@ func TestHowAModelRunsIsChangedWhereItsFileIsShown(t *testing.T) { t.Errorf("on demand was sent as %+v", cat.lastScale) } } + +func TestTheMirrorsTableIsGroupedByModel(t *testing.T) { + // Sorted by state alone, two versions of qwen sat either side of an + // unrelated download; grouped, they are together under one heading. + m := &fakeMirror{models: []mirror.Status{ + {Model: "qwen", Version: "v1", File: "a.gguf", State: mirror.Present, BytesDone: 100}, + {Model: "zeta", Version: "v1", File: "z.gguf", State: mirror.Present, BytesDone: 5}, + {Model: "qwen", Version: "v2", File: "b.gguf", State: mirror.Fetching, BytesDone: 50}, + }} + body := mirrorGet(t, mirrorPage(t, m, true), "/admin/mirror").Body.String() + + if n := strings.Count(body, `class="model-group"`); n != 2 { + t.Fatalf("%d model headings, want 2", n) + } + qwen, zeta := strings.Index(body, "qwen"), strings.Index(body, "zeta") + if qwen < 0 || zeta < 0 || qwen > zeta { + t.Errorf("a model with a download should come first: qwen at %d, zeta at %d", qwen, zeta) + } + // Both of qwen's versions come before zeta's heading. + v1, v2 := strings.Index(body, "v1"), strings.Index(body, "v2") + if v2 > zeta || v1 > zeta { + t.Errorf("qwen's versions are not under its heading: v1 %d v2 %d zeta %d", v1, v2, zeta) + } + if !strings.Contains(body, "2 versions · 150 B") || !strings.Contains(body, `downloading`) { + t.Error("the heading should total its versions and say one is downloading") + } +} diff --git a/internal/web/static/base.css b/internal/web/static/base.css index 7bd2859..5781db3 100644 --- a/internal/web/static/base.css +++ b/internal/web/static/base.css @@ -543,3 +543,8 @@ td.load { white-space: nowrap; min-width: 8.5rem; } .minibar.hot > span { background: var(--bad); } .load-v { font-variant-numeric: tabular-nums; font-size: .85rem; } table.nodes td:first-child code { white-space: nowrap; } +/* The mirror's table, grouped by model: a heading row, then its versions. */ +table.held tr.model-group > td { background: var(--bg); padding-top: .7rem; border-bottom: 1px solid var(--line); } +table.held tr.model-group strong { font-size: .95rem; } +table.held tr.model-version > td:first-child { padding-left: 1.4rem; } +.tag.bad { color: var(--bad); border-color: var(--bad); } diff --git a/internal/web/templates/admin_mirror.html b/internal/web/templates/admin_mirror.html index 643620f..6a60152 100644 --- a/internal/web/templates/admin_mirror.html +++ b/internal/web/templates/admin_mirror.html @@ -31,9 +31,15 @@ reachable from this machine.

What the mirror holds

{{if .Rows}} - -{{range .Rows}} - + +{{range .Groups}} + +{{range .Rows}} + {{end}} {{end}} +{{end}}
ModelFilesSizeRuns
{{.Model}} {{.Version}}
VersionFilesSizeRuns
{{.Model}} + {{len .Rows}} version{{if gt (len .Rows) 1}}s{{end}} · {{bytes .Bytes}} + {{if .Fetching}}downloading{{end}} + {{if .Failed}}failed{{end}} + {{if .InUse}}in use{{end}}
{{.Version}} {{if gt .Files 1}}{{.Files}} files{{else}}{{.File}}{{end}} @@ -163,6 +169,7 @@ job by name if you would rather pin it.

“copy address” gives what a catalog entry's source should say — the file, or for a version of several files the directory, with its