Fix repository sorting and idle time

6f5b28c67fcb5983140505836c836d00568c43a5
Alexis Sellier committed ago 1 parent 60b8dd63
handler.go +16 -0
2 2
3 3
import (
4 4
	"fmt"
5 5
	"io"
6 6
	"net/http"
7 +
	"sort"
7 8
	"strconv"
8 9
	"strings"
9 10
)
10 11
11 12
type pageData struct {
189 190
func (s *server) handleIndex(w http.ResponseWriter, r *http.Request) {
190 191
	type indexData struct {
191 192
		Repos   []*RepoInfo
192 193
		IsEmpty bool
193 194
	}
195 +
196 +
	// Refresh LastUpdated for each repo from its latest commit.
197 +
	for _, repo := range s.repos {
198 +
		defaultBranch := repo.Git.getDefaultBranch()
199 +
		commit, err := repo.Git.getCommit(defaultBranch)
200 +
		if err == nil {
201 +
			repo.LastUpdated = commit.AuthorDate
202 +
		}
203 +
	}
204 +
205 +
	// Re-sort repos by last updated (most recent first).
206 +
	sort.Slice(s.sorted, func(i, j int) bool {
207 +
		return s.repos[s.sorted[i]].LastUpdated.After(s.repos[s.sorted[j]].LastUpdated)
208 +
	})
209 +
194 210
	repos := make([]*RepoInfo, 0, len(s.sorted))
195 211
	for _, name := range s.sorted {
196 212
		repos = append(repos, s.repos[name])
197 213
	}
198 214
	pd := s.newPageData(r, nil, "repositories", "")