From 3dd600114b108715290f21f8541664d778a6cb88 Mon Sep 17 00:00:00 2001 From: Victor Castell Date: Mon, 28 Dec 2015 10:27:23 +0100 Subject: [PATCH] Moved int64arr to utils --- dkron/dashboard.go | 25 +++---------------------- dkron/utils.go | 6 ++++++ 2 files changed, 9 insertions(+), 22 deletions(-) diff --git a/dkron/dashboard.go b/dkron/dashboard.go index 68b00416d..cac74447b 100644 --- a/dkron/dashboard.go +++ b/dkron/dashboard.go @@ -6,7 +6,6 @@ import ( "html/template" "net/http" "path/filepath" - "sort" "github.com/gorilla/mux" ) @@ -17,12 +16,6 @@ const ( apiPathPrefix = "v1" ) -type int64arr []int64 - -func (a int64arr) Len() int { return len(a) } -func (a int64arr) Swap(i, j int) { a[i], a[j] = a[j], a[i] } -func (a int64arr) Less(i, j int) bool { return a[i] < a[j] } - type commonDashboardData struct { Version string LeaderName string @@ -141,18 +134,10 @@ func (a *AgentCommand) dashboardExecutionsHandler(w http.ResponseWriter, r *http vars := mux.Vars(r) job := vars["job"] - execs, _ := a.store.GetExecutions(job) - groups := make(map[int64][]*Execution) - for _, exec := range execs { - groups[exec.Group] = append(groups[exec.Group], exec) - } - - // Build a separate data structure to show in order - var byGroup int64arr - for key := range groups { - byGroup = append(byGroup, key) + groups, byGroup, err := a.store.GetGroupedExecutions(job) + if err != nil { + log.Error(err) } - sort.Sort(byGroup) tmpl := template.Must(template.New("dashboard.html.tmpl").Funcs(template.FuncMap{ "html": func(value []byte) string { @@ -171,10 +156,6 @@ func (a *AgentCommand) dashboardExecutionsHandler(w http.ResponseWriter, r *http }, }).ParseFiles(templateSet(a.config.UIDir, "executions")...)) - if len(execs) > 100 { - execs = execs[len(execs)-100:] - } - data := struct { Common *commonDashboardData Groups map[int64][]*Execution diff --git a/dkron/utils.go b/dkron/utils.go index 2718b2d7c..7d1d328f9 100644 --- a/dkron/utils.go +++ b/dkron/utils.go @@ -19,3 +19,9 @@ func generateSlug(str string) (slug string) { return -1 }, strings.ToLower(strings.TrimSpace(str))) } + +type int64arr []int64 + +func (a int64arr) Len() int { return len(a) } +func (a int64arr) Swap(i, j int) { a[i], a[j] = a[j], a[i] } +func (a int64arr) Less(i, j int) bool { return a[i] < a[j] }