Sort personal projects by recency instead of randomly

This commit is contained in:
Ben Visness 2021-11-11 16:35:00 -08:00
parent b41fb365cf
commit 8f560de2b6
1 changed files with 5 additions and 3 deletions

View File

@ -114,9 +114,11 @@ func ProjectIndex(c *RequestContext) ResponseData {
return c.ErrorResponse(http.StatusInternalServerError, oops.New(err, "failed to fetch personal projects")) return c.ErrorResponse(http.StatusInternalServerError, oops.New(err, "failed to fetch personal projects"))
} }
randSeed := now.YearDay() sort.Slice(projects, func(i, j int) bool {
random := rand.New(rand.NewSource(int64(randSeed))) p1 := projects[i].Project
random.Shuffle(len(projects), func(i, j int) { projects[i], projects[j] = projects[j], projects[i] }) p2 := projects[j].Project
return p2.AllLastUpdated.Before(p1.AllLastUpdated) // sort backwards - recent first
})
for i, p := range projects { for i, p := range projects {
if i >= maxPersonalProjects { if i >= maxPersonalProjects {